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