Kotlinlearncs.online LogoJava
Return to List

Test Writing: Count DNA Subsequence

Created By: Geoffrey Challen
/ Version: 2021.2.0

Declare and implement a method called countDNASubsequence. It should take two nullable String arguments: the first a strand of DNA to examine, and the second a sequence to look for. It should return as an Int the number of nonoverlapping times that the sequence appears in the strand. Both the strand and the sequence will be entirely made up of only the characters 'A', 'T', 'G', and 'C', corresponding to the DNA base pairs.

For example, given the DNA strand AAAAAAAA and the sequence AA you should return 4, not 7, since the subsequence AA only appears 4 non-overlapping times in the strand.

If DNA or sequence is null or empty you should return 0.

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Kotlin's assert or check methods