BonusTest.java 2.8KB

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