Datasets:
Download raw/java/cwe_1041_1_funct_test.java from amazon/AutoSUIT: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/datasets/amazon/AutoSUIT/resolve/main/raw/java/cwe_1041_1_funct_test.java
- Command line
-
hf download hf://datasets/amazon/AutoSUIT/raw/java/cwe_1041_1_funct_test.java
-
curl -L -o cwe_1041_1_funct_test.java https://huggingface.co/datasets/amazon/AutoSUIT/resolve/main/raw/java/cwe_1041_1_funct_test.java
2.25 kB
| import org.junit.jupiter.api.*; | |
| import static org.junit.jupiter.api.Assertions.*; | |
| import static org.mockito.Mockito.*; | |
| class SurfaceAreaCalculatorTest { | |
| // Test for Example 1: r = 1.0, s = 10.0 | |
| void testCalculateSurfaceAreaExample1() { | |
| SurfaceAreaCalculator calculator = new SurfaceAreaCalculator(); | |
| double r = 1.0; | |
| double s = 10.0; | |
| double expected = Math.PI * r * s + Math.PI * Math.pow(r, 2); // expected result: 34.5575... | |
| double result = calculator.calculateSurfaceArea(r, s); | |
| assertEquals(expected, result, 0.0001, "Surface area should be calculated correctly for r=1.0, s=10.0"); | |
| } | |
| // Test for Example 2: r = 2.0, s = 5.0 | |
| void testCalculateSurfaceAreaExample2() { | |
| SurfaceAreaCalculator calculator = new SurfaceAreaCalculator(); | |
| double r = 2.0; | |
| double s = 5.0; | |
| double expected = Math.PI * r * s + Math.PI * Math.pow(r, 2); // expected result: 43.9822... | |
| double result = calculator.calculateSurfaceArea(r, s); | |
| assertEquals(expected, result, 0.0001, "Surface area should be calculated correctly for r=2.0, s=5.0"); | |
| } | |
| // Test for Example 3: r = 0.5, s = 4.0 | |
| void testCalculateSurfaceAreaExample3() { | |
| SurfaceAreaCalculator calculator = new SurfaceAreaCalculator(); | |
| double r = 0.5; | |
| double s = 4.0; | |
| double expected = Math.PI * r * s + Math.PI * Math.pow(r, 2); // expected result: 9.4247... | |
| double result = calculator.calculateSurfaceArea(r, s); | |
| assertEquals(expected, result, 0.0001, "Surface area should be calculated correctly for r=0.5, s=4.0"); | |
| } | |
| // Test for zero radius case: r = 0.0, s = 4.0 | |
| void testCalculateSurfaceAreaZeroRadius() { | |
| SurfaceAreaCalculator calculator = new SurfaceAreaCalculator(); | |
| double r = 0.0; | |
| double s = 4.0; | |
| double expected = 0.0; // No surface area should be calculated | |
| double result = calculator.calculateSurfaceArea(r, s); | |
| assertEquals(expected, result, 0.0001, "Surface area should be zero for r=0.0, s=4.0"); | |
| } | |
| } | |