LoopFunTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package QuizWeek1;
  2. import static org.junit.Assert.*;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. public class LoopFunTest
  7. {
  8. private LoopFun loop;
  9. @Before
  10. public void setUp(){
  11. loop = new LoopFun();
  12. }
  13. @Test
  14. public void testFactorialBase(){
  15. //Given
  16. int number = 1;
  17. int expected = 1;
  18. //When
  19. int actual = loop.factorial(number);
  20. //Then
  21. assertEquals(expected, actual);
  22. }
  23. @Test
  24. public void testFactorialOfSmallNumber(){
  25. //Given
  26. int number = 3;
  27. int expected = 6;
  28. //When
  29. int actual = loop.factorial(number);
  30. //Then
  31. assertEquals(expected, actual);
  32. }
  33. @Test
  34. public void testFactorialOfBigNumber(){
  35. //Given
  36. int number = 6;
  37. int expected = 720;
  38. //When
  39. int actual = loop.factorial(number);
  40. //Then
  41. assertEquals(expected, actual);
  42. }
  43. @Test
  44. public void testAcronymBasic() {
  45. //Given
  46. String phrase = "Portable Network Graphics";
  47. String expected = "PNG";
  48. //When
  49. String actual = loop.acronym(phrase);
  50. //Then
  51. assertEquals(expected, actual);
  52. }
  53. @Test
  54. public void testAcronymBasicLowercaseWords() {
  55. //Given
  56. String phrase = "Ruby on Rails";
  57. String expected = "ROR";
  58. //When
  59. String actual = loop.acronym(phrase);
  60. //Then
  61. assertEquals(expected, actual);
  62. }
  63. @Test
  64. public void testAcronymBasicPunctuation() {
  65. //Given
  66. String phrase = "First In, First Out";
  67. String expected = "FIFO";
  68. //When
  69. String actual = loop.acronym(phrase);
  70. //Then
  71. assertEquals(expected, actual);
  72. }
  73. @Test
  74. public void testAcronymBasicNonAcronymAllCapsWord() {
  75. //Given
  76. String phrase = "GNU Image Manipulation Program";
  77. String expected = "GIMP";
  78. //When
  79. String actual = loop.acronym(phrase);
  80. //Then
  81. assertEquals(expected, actual);
  82. }
  83. @Test
  84. public void testEncryptWithTheFirstAlphabet(){
  85. //Given
  86. String word = "apple";
  87. String expected = "dssoh";
  88. //When
  89. String actual = loop.encrypt(word);
  90. //Then
  91. assertEquals(expected, actual);
  92. }
  93. @Test
  94. public void testEncryptWithTheLastLetters(){
  95. //Given
  96. String word = "wxyz";
  97. String expected = "zabc";
  98. //When
  99. String actual = loop.encrypt(word);
  100. //Then
  101. assertEquals(expected, actual);
  102. }
  103. }