lots of exercises in java... from https://github.com/exercism/java

NucleotideTest.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import org.junit.Ignore;
  2. import org.junit.Test;
  3. import org.junit.Rule;
  4. import org.junit.rules.ExpectedException;
  5. import java.util.Map;
  6. import static org.hamcrest.Matchers.*;
  7. import static org.junit.Assert.*;
  8. public class NucleotideTest {
  9. @Rule
  10. public ExpectedException thrown = ExpectedException.none();
  11. @Test
  12. public void testEmptyDnaStringHasNoAdenine() {
  13. DNA dna = new DNA("");
  14. assertThat(dna.count('A'), is(0));
  15. }
  16. @Ignore
  17. @Test
  18. public void testEmptyDnaStringHasNoNucleotides() {
  19. DNA dna = new DNA("");
  20. Map<Character, Integer> counts = dna.nucleotideCounts();
  21. assertThat(counts.size(), is(4));
  22. assertThat(counts, allOf(
  23. hasEntry('A', 0),
  24. hasEntry('C', 0),
  25. hasEntry('G', 0),
  26. hasEntry('T', 0)
  27. ));
  28. }
  29. @Ignore
  30. @Test
  31. public void testRepetitiveCytosineGetsCounted() {
  32. DNA dna = new DNA("CCCCC");
  33. assertThat(dna.count('C'), is(5));
  34. }
  35. @Ignore
  36. @Test
  37. public void testRepetitiveSequenceWithOnlyGuanine() {
  38. DNA dna = new DNA("GGGGGGGG");
  39. Map<Character, Integer> counts = dna.nucleotideCounts();
  40. assertThat(counts.size(), is(4));
  41. assertThat(counts, allOf(
  42. hasEntry('A', 0),
  43. hasEntry('C', 0),
  44. hasEntry('G', 8),
  45. hasEntry('T', 0)
  46. ));
  47. }
  48. @Ignore
  49. @Test
  50. public void testCountsOnlyThymine() {
  51. DNA dna = new DNA("GGGGGTAACCCGG");
  52. assertThat(dna.count('T'), is(1));
  53. }
  54. @Ignore
  55. @Test
  56. public void testCountsANucleotideOnlyOnce() {
  57. DNA dna = new DNA("CGATTGGG");
  58. dna.count('T');
  59. assertThat(dna.count('T'), is(2));
  60. }
  61. @Ignore
  62. @Test
  63. public void testDnaCountsDoNotChangeAfterCountingAdenine() {
  64. DNA dna = new DNA("GATTACA");
  65. dna.count('A');
  66. Map<Character, Integer> counts = dna.nucleotideCounts();
  67. assertThat(counts.size(), is(4));
  68. assertThat(counts, allOf(
  69. hasEntry('A', 3),
  70. hasEntry('C', 1),
  71. hasEntry('G', 1),
  72. hasEntry('T', 2)
  73. ));
  74. }
  75. @Ignore
  76. @Test
  77. public void testValidatesNucleotides() {
  78. thrown.expect(IllegalArgumentException.class);
  79. DNA dna = new DNA("GACT");
  80. dna.count('X');
  81. }
  82. @Ignore
  83. @Test
  84. public void testCountsAllNucleotides() {
  85. String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
  86. DNA dna = new DNA(s);
  87. Map<Character, Integer> counts = dna.nucleotideCounts();
  88. assertThat(counts.size(), is(4));
  89. assertThat(counts, allOf(
  90. hasEntry('A', 20),
  91. hasEntry('C', 12),
  92. hasEntry('G', 17),
  93. hasEntry('T', 21)
  94. ));
  95. }
  96. }