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

NucleotideTest.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import static org.assertj.core.api.Assertions.assertThat;
  2. import static org.assertj.core.api.Assertions.entry;
  3. import org.junit.Test;
  4. import org.junit.Ignore;
  5. public class NucleotideTest {
  6. @Test
  7. public void testEmptyDnaStringHasNoAdenosine() {
  8. DNA dna = new DNA("");
  9. assertThat(dna.count('A')).isEqualTo(0);
  10. }
  11. @Ignore
  12. @Test
  13. public void testEmptyDnaStringHasNoNucleotides() {
  14. DNA dna = new DNA("");
  15. assertThat(dna.nucleotideCounts()).hasSize(4).contains(
  16. entry('A', 0),
  17. entry('C', 0),
  18. entry('G', 0),
  19. entry('T', 0)
  20. );
  21. }
  22. @Ignore
  23. @Test
  24. public void testRepetitiveCytidineGetsCounted() {
  25. DNA dna = new DNA("CCCCC");
  26. assertThat(dna.count('C')).isEqualTo(5);
  27. }
  28. @Ignore
  29. @Test
  30. public void testRepetitiveSequenceWithOnlyGuanosine() {
  31. DNA dna = new DNA("GGGGGGGG");
  32. assertThat(dna.nucleotideCounts()).hasSize(4).contains(
  33. entry('A', 0),
  34. entry('C', 0),
  35. entry('G', 8),
  36. entry('T', 0)
  37. );
  38. }
  39. @Ignore
  40. @Test
  41. public void testCountsOnlyThymidine() {
  42. DNA dna = new DNA("GGGGGTAACCCGG");
  43. assertThat(dna.count('T')).isEqualTo(1);
  44. }
  45. @Ignore
  46. @Test
  47. public void testCountsANucleotideOnlyOnce() {
  48. DNA dna = new DNA("CGATTGGG");
  49. dna.count('T');
  50. assertThat(dna.count('T')).isEqualTo(2);
  51. }
  52. @Ignore
  53. @Test
  54. public void testDnaCountsDoNotChangeAfterCountingAdenosine() {
  55. DNA dna = new DNA("GATTACA");
  56. dna.count('A');
  57. assertThat(dna.nucleotideCounts()).hasSize(4).contains(
  58. entry('A', 3),
  59. entry('C', 1),
  60. entry('G', 1),
  61. entry('T', 2)
  62. );
  63. }
  64. @Ignore
  65. @Test(expected = IllegalArgumentException.class)
  66. public void testValidatesNucleotides() {
  67. DNA dna = new DNA("GACT");
  68. dna.count('X');
  69. }
  70. @Ignore
  71. @Test
  72. public void testCountsAllNucleotides() {
  73. String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
  74. DNA dna = new DNA(s);
  75. assertThat(dna.nucleotideCounts()).hasSize(4).contains(
  76. entry('A', 20),
  77. entry('C', 12),
  78. entry('G', 17),
  79. entry('T', 21)
  80. );
  81. }
  82. }