Kirk Rader  1.0-SNAPSHOT
PythagorasTest.java
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Kirk Rader
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package us.rader.usingdoxygen.test;
18 
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.fail;
21 
22 import org.junit.Test;
23 
25 
26 /**
27  * Unit tests for {@link Pythagoras}.
28  */
29 public class PythagorasTest {
30 
31  /**
32  * First leg of the right triangle.
33  */
34  public static final double LEG1 = 2.0;
35 
36  /**
37  * Second leg of the right triangle.
38  */
39  public static final double LEG2 = 3.0;
40 
41  /**
42  * 3.6055 is the square root of 13 truncated to four decimal places.
43  *
44  * This is the approximate hypotenuse of a right triangle with legs of
45  * length {@link #LEG1} and {@link #LEG2}.
46  */
47  public static final double HYPOTENUSE = 3.6055;
48 
49  /**
50  * Verify that {@link Pythagoras#calculateLeg} throws the expected exception
51  * when passed too small a number for its second argument.
52  */
53  @Test
54  public void hypotenuseLessThanLegTest() {
55 
56  try {
57 
58  Pythagoras.calculateLeg(LEG1, LEG1 - 0.1);
59  fail("IllegalArgumentException e");
60 
61  } catch (@SuppressWarnings("unused") final IllegalArgumentException e) { // NOSONAR
62 
63  // success
64 
65  }
66  }
67 
68  /**
69  * Verify that {@link Pythagoras#calculateHypotenuse} throws the expected
70  * exception when passed a negative number for its first argument.
71  */
72  @Test
73  public void negativeFirstLegTest() {
74 
75  try {
76 
77  Pythagoras.calculateHypotenuse(-LEG1, LEG2);
78  fail("IllegalArgumentException e");
79 
80  } catch (@SuppressWarnings("unused") final IllegalArgumentException e) { // NOSONAR
81 
82  // success
83 
84  }
85  }
86 
87  /**
88  * Verify that {@link Pythagoras#calculateLeg} throws the expected exception
89  * when passed a negative number for its first argument.
90  */
91  @Test
92  public void negativeLegTest() {
93 
94  try {
95 
96  Pythagoras.calculateLeg(-LEG1, HYPOTENUSE);
97  fail("IllegalArgumentException e");
98 
99  } catch (@SuppressWarnings("unused") final IllegalArgumentException e) { // NOSONAR
100 
101  // success
102 
103  }
104  }
105 
106  /**
107  * Verify that {@link Pythagoras#calculateHypotenuse} throws the expected
108  * exception when passed a negative number for its first argument.
109  */
110  @Test
111  public void negativeSecondLegTest() {
112 
113  try {
114 
115  Pythagoras.calculateHypotenuse(LEG1, -LEG2);
116  fail("IllegalArgumentException e");
117 
118  } catch (@SuppressWarnings("unused") final IllegalArgumentException e) { // NOSONAR
119 
120  // success
121 
122  }
123  }
124 
125  /**
126  * Verify that {@link Pythagoras#calculateLeg} returns the expected value
127  * when passed two positive numbers such that the second is greater than the
128  * first
129  */
130  @Test
132 
133  assertTrue(LEG2 - Pythagoras.calculateLeg(LEG1, HYPOTENUSE) < 0.0001);
134 
135  }
136 
137  /**
138  * Verify that {@link Pythagoras#calculateHypotenuse} returns the expected
139  * value when passed two positive numbers.
140  */
141  @Test
143 
144  assertTrue(HYPOTENUSE - Pythagoras.calculateHypotenuse(LEG1, LEG2) < 0.0001);
145 
146  }
147 
148 }
Examples of javadoc comment blocks with rich content supported by Doxygen.
Definition: Base.java:17
void positiveLegsHypotenuseTest()
Verify that Pythagoras#calculateHypotenuse returns the expected value when passed two positive number...
static double calculateHypotenuse(final double leg1, final double leg2)
Calculate the hypotenuse of a right triangle whose legs are of lengths leg1 and leg2.
Definition: Pythagoras.java:65
void negativeLegTest()
Verify that Pythagoras#calculateLeg throws the expected exception when passed a negative number for i...
static final double HYPOTENUSE
3.6055 is the square root of 13 truncated to four decimal places.
Permutations of the Pythagorean theorem.
Definition: Pythagoras.java:34
static final double LEG2
Second leg of the right triangle.
void negativeFirstLegTest()
Verify that Pythagoras#calculateHypotenuse throws the expected exception when passed a negative numbe...
void positiveLegAndHypotenuseLegTest()
Verify that Pythagoras#calculateLeg returns the expected value when passed two positive numbers such ...
void negativeSecondLegTest()
Verify that Pythagoras#calculateHypotenuse throws the expected exception when passed a negative numbe...
static final double LEG1
First leg of the right triangle.
void hypotenuseLessThanLegTest()
Verify that Pythagoras#calculateLeg throws the expected exception when passed too small a number for ...
static double calculateLeg(final double leg, final double hypotenuse)
Calculate the length of the remaining leg of a right triangle given the length of one leg and its hyp...