SHOW:
|
|
- or go back to the newest paste.
1 | package task.to.soft; | |
2 | ||
3 | - | import java.io.*; |
3 | + | import static org.junit.Assert.*; |
4 | - | import java.util.*; |
4 | + | import org.junit.*; |
5 | ||
6 | - | abstract class FigureGeneral { |
6 | + | public class AbsFigureTest { |
7 | - | private double width; |
7 | + | |
8 | - | private double height; |
8 | + | @Test |
9 | - | private String name; |
9 | + | public void testRectArea() { |
10 | - | |
10 | + | Rectangle rectangle = new Rectangle(2.0, 2.0, "rectangle"); |
11 | - | FigureGeneral(double width, double height, String name){ |
11 | + | double testResult = 4; |
12 | - | this.width = width; |
12 | + | double actualResult = rectangle.area(); |
13 | - | this.height = height; |
13 | + | float delta = 0.0001f; |
14 | - | this.name = name; |
14 | + | assertEquals(testResult, actualResult, delta); |
15 | } | |
16 | - | |
16 | + | |
17 | - | double getWidth(){ return width; } |
17 | + | @Test |
18 | - | double getHeight(){ return height; } |
18 | + | public void testTriangleArea() { |
19 | - | void setWidth(double width){ this.width = width; } |
19 | + | Triangle triangle = new Triangle(2.0, 2.0, "triangle"); |
20 | - | void setHeight(double height){ this.height = height; } |
20 | + | double testResult = 2; |
21 | - | |
21 | + | double actualResult = triangle.area(); |
22 | - | String getName(){ return name; } |
22 | + | float delta = 0.0001f; |
23 | - | |
23 | + | assertEquals(testResult, actualResult, delta); |
24 | - | abstract public double area(); |
24 | + | } |
25 | - | |
25 | + | |
26 | - | public String toString(){ |
26 | + | @Test |
27 | - | return getName() + " " + getHeight()+ " " + getWidth(); |
27 | + | public void testToStringFormat() { |
28 | Triangle triangle = new Triangle(2.0, 2.0, "triangle"); | |
29 | - | } |
29 | + | String testResult = "triangle 2.0 2.0"; |
30 | assertEquals(testResult, triangle.toString()); | |
31 | - | class Triangle extends FigureGeneral { |
31 | + | |
32 | - | |
32 | + | |
33 | - | Triangle(double width, double height, String name) { |
33 | + | @Test |
34 | - | super(width, height, "triangle"); |
34 | + | public void testCompareMore() { |
35 | FigureGeneral oneFigure = new Rectangle(2.0, 2.0, "rectangle"); | |
36 | FigureGeneral twoFigure = new Triangle(1.0, 2.0, "triangle"); | |
37 | - | public double area() { |
37 | + | boolean actualResult = oneFigure.area() > twoFigure.area(); |
38 | - | return (getWidth() * getHeight()) / 2; |
38 | + | boolean expextedResult = true; |
39 | assertEquals(expextedResult, actualResult); | |
40 | - | } |
40 | + | } |
41 | ||
42 | - | class Rectangle extends FigureGeneral { |
42 | + | @Test |
43 | - | |
43 | + | public void testCompareLess() { |
44 | - | Rectangle(double width, double height, String name) { |
44 | + | FigureGeneral oneFigure = new Rectangle(1.0, 2.0, "rectangle"); |
45 | - | super(width, height, "rectangle"); |
45 | + | FigureGeneral twoFigure = new Triangle(2.0, 2.0, "triangle"); |
46 | boolean actualResult = oneFigure.area() > twoFigure.area(); | |
47 | boolean expextedResult = false; | |
48 | - | public double area() { |
48 | + | assertEquals(expextedResult, actualResult); |
49 | - | return getWidth() * getHeight(); |
49 | + | } |
50 | ||
51 | - | } |
51 | + | @Test |
52 | public void testCompareEquals() { | |
53 | - | @SuppressWarnings("serial") |
53 | + | FigureGeneral oneFigure = new Rectangle(2.0, 2.0, "rectangle"); |
54 | - | class FigureGeneralFilesFoundException extends Exception { |
54 | + | FigureGeneral twoFigure = new Triangle(2.0, 2.0, "triangle"); |
55 | - | public FigureGeneralFilesFoundException() { |
55 | + | boolean actualResult = oneFigure.area() > twoFigure.area() & |
56 | - | } |
56 | + | oneFigure.area() < twoFigure.area(); |
57 | - | |
57 | + | boolean expextedResult = false; |
58 | - | public FigureGeneralFilesFoundException(String message) { |
58 | + | assertEquals(expextedResult, actualResult); |
59 | - | super(message); |
59 | + | } |
60 | - | } |
60 | + | |
61 | - | } |
61 | + | |
62 | - | |
62 | + |