July 2023
Intermediate to advanced
276 pages
6h 55m
English
The imperative style code you see in this section was sent to me by a developer who was interested in applying functional programming and was curious to learn how to refactor it into the functional style. The code creates Pythagorean triples[19] of positive numbers (a, b, c) which satisfy the condition a2 + b2 = c2.
Let’s start with a few tests to verify the results of the compute method of a PythagoreanTriples class:
| | public class PythagoreanTriplesTest { |
| | PythagoreanTriples pythagoreanTriples; |
| | |
| | @BeforeEach |
| | public void init() { |
| | pythagoreanTriples = new PythagoreanTriples(); |
| | } |
| | |
| | @Test |
| | public void compute() { |
| | assertAll( |
| | () -> assertEquals(List.of(), ... |
Read now
Unlock full access