Skip to content

Commit

Permalink
chap02. tdd란?
Browse files Browse the repository at this point in the history
  • Loading branch information
sangminee committed Jan 8, 2023
1 parent ef44e0f commit 64a65e1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/chap02/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package chap02;

public class Calculator {

public static int plus(int a1, int a2) {
return a1+a2;
}
}
15 changes: 15 additions & 0 deletions src/test/java/chap02/CalculatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package chap02;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CalculatorTest {

@Test
void plus(){
int result = Calculator.plus(1, 2);
assertEquals(3, result);
assertEquals(5, Calculator.plus(4,1));
}
}
5 changes: 5 additions & 0 deletions src/test/java/chap02/PasswordStrength.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package chap02;

public enum PasswordStrength {
NORMAL, STRONG
}
8 changes: 8 additions & 0 deletions src/test/java/chap02/PasswordStrengthMeter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package chap02;

public class PasswordStrengthMeter {
public PasswordStrength meter(String s) {
if(s.length() < 8) return PasswordStrength.NORMAL;
return PasswordStrength.STRONG;
}
}
25 changes: 25 additions & 0 deletions src/test/java/chap02/PasswordStrengthMeterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package chap02;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class PasswordStrengthMeterTest {
@Test
void meetsAllCriteria_Then_Strong(){
PasswordStrengthMeter meter = new PasswordStrengthMeter();
PasswordStrength result = meter.meter("abcd!@AB");
assertEquals(PasswordStrength.STRONG, result);
PasswordStrength result2 = meter.meter("abcd!Add");
assertEquals(PasswordStrength.STRONG, result2);
}

@Test
void meetsOtherCriteria_except_for_Length_Then_Normal(){
PasswordStrengthMeter meter = new PasswordStrengthMeter();
PasswordStrength result = meter.meter("abcd!@A");
assertEquals(PasswordStrength.NORMAL, result);
PasswordStrength result2 = meter.meter("abcd!c");
assertEquals(PasswordStrength.NORMAL, result2);
}
}

0 comments on commit 64a65e1

Please sign in to comment.