File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
src/test/java/com/thealgorithms/physics Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .thealgorithms .physics ;
2+
3+ import static org .junit .jupiter .api .Assertions .*;
4+ import org .junit .jupiter .api .Test ;
5+
6+ public class SnellsLawTest {
7+ //tests for example environmet
8+ @ Test
9+ public void testCalculateRefractionAngle () {
10+ double n1 = 1.0 ; // air
11+ double n2 = 1.5 ; // glass
12+ double theta1 = Math .toRadians (30 ); // 30 grados
13+
14+ double theta2 = SnellsLaw .calculateRefractionAngle (n1 , n2 , theta1 );
15+
16+ // expected value using: sin(theta2) = n1/n2 * sin(theta1)
17+ double expected = Math .asin ((n1 / n2 ) * Math .sin (theta1 ));
18+
19+ assertEquals (expected , theta2 , 1e-9 );
20+ }
21+ //tests for total refraction
22+ @ Test
23+ public void testInvalidRefractiveIndex () {
24+ assertThrows (IllegalArgumentException .class , () -> {
25+ SnellsLaw .calculateRefractionAngle (-1 , 1.5 , 0.5 );
26+ });
27+
28+ assertThrows (IllegalArgumentException .class , () -> {
29+ SnellsLaw .calculateRefractionAngle (1 , 0 , 0.5 );
30+ });
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments