1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/individualsamples/src/org/apidesign/samples/HundredPercentCoverage.java Sat Jun 14 09:58:17 2008 +0200
1.3 @@ -0,0 +1,16 @@
1.4 +package org.apidesign.samples;
1.5 +
1.6 +public class HundredPercentCoverage {
1.7 + // BEGIN: hundred.percent
1.8 + private int sum = 10;
1.9 +
1.10 + public int add(int x) {
1.11 + sum += x;
1.12 + return sum;
1.13 + }
1.14 +
1.15 + public int percentageFrom(int howMuch) {
1.16 + return 100 * howMuch / sum;
1.17 + }
1.18 + // END: hundred.percent
1.19 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/samples/individualsamples/test/org/apidesign/samples/HundredPercentCoverageTest.java Sat Jun 14 09:58:17 2008 +0200
2.3 @@ -0,0 +1,32 @@
2.4 +package org.apidesign.samples;
2.5 +
2.6 +import org.junit.After;
2.7 +import org.junit.AfterClass;
2.8 +import org.junit.Before;
2.9 +import org.junit.BeforeClass;
2.10 +import org.junit.Test;
2.11 +import static org.junit.Assert.*;
2.12 +
2.13 +public class HundredPercentCoverageTest {
2.14 + HundredPercentCoverage instance;
2.15 +
2.16 + public HundredPercentCoverageTest() {
2.17 + }
2.18 +
2.19 + @Before
2.20 + public void setUp() {
2.21 + instance = new HundredPercentCoverage();
2.22 + }
2.23 +
2.24 + @Test
2.25 + public void cover100PercentOfAllLinesBlocksAndStatements() {
2.26 + assertEquals("init value + 5", 15, instance.add(5));
2.27 + assertEquals("division", 20, instance.percentageFrom(3));
2.28 + }
2.29 +
2.30 + @Test
2.31 + public void stillThereIsAWayToFail() {
2.32 + assertEquals("init value - 10", 0, instance.add(-10));
2.33 + assertEquals("division", 0, instance.percentageFrom(30));
2.34 + }
2.35 +}
2.36 \ No newline at end of file