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

HammingTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import org.junit.Ignore;
  2. import org.junit.Rule;
  3. import org.junit.Test;
  4. import org.junit.rules.ExpectedException;
  5. import static org.junit.Assert.assertEquals;
  6. /*
  7. * version: 1.1.0
  8. */
  9. public class HammingTest {
  10. @Rule
  11. public ExpectedException expectedException = ExpectedException.none();
  12. @Test
  13. public void testNoDistanceBetweenEmptyStrands() {
  14. assertEquals(0, new Hamming("", "").getHammingDistance());
  15. }
  16. @Ignore("Remove to run test")
  17. @Test
  18. public void testNoDistanceBetweenShortIdenticalStrands() {
  19. assertEquals(0, new Hamming("A", "A").getHammingDistance());
  20. }
  21. @Ignore("Remove to run test")
  22. @Test
  23. public void testNoDistanceBetweenLongIdenticalStrands() {
  24. assertEquals(0, new Hamming("GGACTGA", "GGACTGA").getHammingDistance());
  25. }
  26. @Ignore("Remove to run test")
  27. @Test
  28. public void testCompleteDistanceInSingleNucleotideStrand() {
  29. assertEquals(1, new Hamming("A", "G").getHammingDistance());
  30. }
  31. @Ignore("Remove to run test")
  32. @Test
  33. public void testCompleteDistanceInSmallStrand() {
  34. assertEquals(2, new Hamming("AG", "CT").getHammingDistance());
  35. }
  36. @Ignore("Remove to run test")
  37. @Test
  38. public void testSmallDistanceInSmallStrand() {
  39. assertEquals(1, new Hamming("AT", "CT").getHammingDistance());
  40. }
  41. @Ignore("Remove to run test")
  42. @Test
  43. public void testSmallDistanceInMediumStrand() {
  44. assertEquals(1, new Hamming("GGACG", "GGTCG").getHammingDistance());
  45. }
  46. @Ignore("Remove to run test")
  47. @Test
  48. public void testSmallDistanceInLongStrand() {
  49. assertEquals(2, new Hamming("ACCAGGG", "ACTATGG").getHammingDistance());
  50. }
  51. @Ignore("Remove to run test")
  52. @Test
  53. public void testNonUniqueCharacterInFirstStrand() {
  54. assertEquals(1, new Hamming("AGA", "AGG").getHammingDistance());
  55. }
  56. @Ignore("Remove to run test")
  57. @Test
  58. public void testNonUniqueCharacterInSecondStrand() {
  59. assertEquals(1, new Hamming("AGG", "AGA").getHammingDistance());
  60. }
  61. @Ignore("Remove to run test")
  62. @Test
  63. public void testSameNucleotidesInDifferentPositions() {
  64. assertEquals(2, new Hamming("TAG", "GAT").getHammingDistance());
  65. }
  66. @Ignore("Remove to run test")
  67. @Test
  68. public void testLargeDistanceInPermutedStrand() {
  69. assertEquals(4, new Hamming("GATACA", "GCATAA").getHammingDistance());
  70. }
  71. @Ignore("Remove to run test")
  72. @Test
  73. public void testLargeDistanceInOffByOneStrand() {
  74. assertEquals(9, new Hamming("GGACGGATTCTG", "AGGACGGATTCT").getHammingDistance());
  75. }
  76. @Ignore("Remove to run test")
  77. @Test
  78. public void testValidatesFirstStrandNotLonger() {
  79. expectedException.expect(IllegalArgumentException.class);
  80. expectedException.expectMessage("leftStrand and rightStrand must be of equal length.");
  81. new Hamming("AATG", "AAA");
  82. }
  83. @Ignore("Remove to run test")
  84. @Test
  85. public void testValidatesSecondStrandNotLonger() {
  86. expectedException.expect(IllegalArgumentException.class);
  87. expectedException.expectMessage("leftStrand and rightStrand must be of equal length.");
  88. new Hamming("ATA", "AGTG");
  89. }
  90. }