diff options
author | Haidong Ji | 2018-12-19 20:36:14 -0600 |
---|---|---|
committer | Haidong Ji | 2018-12-19 20:36:14 -0600 |
commit | f76bab93b3b58df4510a480d28e547125b5f3020 (patch) | |
tree | 51e05f245c3f87d78cea3b216e356700a1e7e839 /AlgoDesignAndTechniqueEdxJava/tests/PrimitiveCalculatorTest.java | |
parent | 1e7ce107613c578fdb99d3480e2e04e351434ac6 (diff) |
Primitive Calculator done!
Once again, this is a challenging but fun puzzle to solve. Key
reflections are:
1. It pays to read and try to understand the problem as early as
possible. "Sleeping on it" really, really helps. Deep appreciation and
clarity came as I was thinking about it before falling asleep, walking
the dogs, and just be;
2. Small steps, but do take them! They lead to success! Hooray :)
Diffstat (limited to 'AlgoDesignAndTechniqueEdxJava/tests/PrimitiveCalculatorTest.java')
-rw-r--r-- | AlgoDesignAndTechniqueEdxJava/tests/PrimitiveCalculatorTest.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/AlgoDesignAndTechniqueEdxJava/tests/PrimitiveCalculatorTest.java b/AlgoDesignAndTechniqueEdxJava/tests/PrimitiveCalculatorTest.java new file mode 100644 index 0000000..11787d4 --- /dev/null +++ b/AlgoDesignAndTechniqueEdxJava/tests/PrimitiveCalculatorTest.java @@ -0,0 +1,40 @@ +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.junit.jupiter.api.Test; + +class PrimitiveCalculatorTest { + + @Test + void test() { + List<Integer> result = new ArrayList<Integer>(); + result.add(1); + assertEquals(result, PrimitiveCalculator.optimal_sequence(1)); + } + + @Test + void test1() { + assertEquals(3, PrimitiveCalculator.optimal_sequence(5).size() - 1); + } + + @Test + void test6() { + assertEquals(2, PrimitiveCalculator.optimal_sequence(6).size() - 1); + } + + @Test + void test2() { + assertEquals(14, PrimitiveCalculator.optimal_sequence(96234).size() - 1); + } + + @Test + void test2DimensionalArraySorting() { + int a[][] = { { 2, 2 }, { 1, 3 }, { 3, 3 } }; + Arrays.sort(a, Comparator.comparingInt(arr -> arr[0])); + assertEquals(1, a[0][0]); + } +} |