File tree 3 files changed +83
-1
lines changed
main/java/com/thealgorithms/maths
test/java/com/thealgorithms/maths 3 files changed +83
-1
lines changed Original file line number Diff line number Diff line change 12
12
<project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
13
13
<maven .compiler.source>17</maven .compiler.source>
14
14
<maven .compiler.target>17</maven .compiler.target>
15
- <assertj .version>3.22.0 </assertj .version>
15
+ <assertj .version>3.23.1 </assertj .version>
16
16
</properties >
17
17
18
18
<dependencyManagement >
31
31
<dependency >
32
32
<groupId >org.junit.jupiter</groupId >
33
33
<artifactId >junit-jupiter</artifactId >
34
+ <version >5.9.0</version >
34
35
<scope >test</scope >
35
36
</dependency >
36
37
<dependency >
37
38
<groupId >org.assertj</groupId >
38
39
<artifactId >assertj-core</artifactId >
39
40
<version >${assertj.version} </version >
40
41
</dependency >
42
+ <dependency >
43
+ <groupId >org.junit.jupiter</groupId >
44
+ <artifactId >junit-jupiter-api</artifactId >
45
+ <version >5.9.0</version >
46
+ <scope >import</scope >
47
+ </dependency >
41
48
</dependencies >
42
49
43
50
<build >
Original file line number Diff line number Diff line change
1
+ package com .thealgorithms .maths ;
2
+
3
+ public class Perimeter {
4
+ public static void main (String [] args ) {
5
+ System .out .println (perimeter_polygon (5 ,4 ));
6
+ System .out .println (perimeter_rectangle (3 ,4 ));
7
+ System .out .printf ("%,3f" ,circumference (5 ));
8
+ }
9
+ // Perimeter of different 2D geometrical shapes
10
+ /**
11
+ *Calculate the Perimeter of polygon.
12
+ * @parameter length of side.
13
+ * @parameter number of sides.
14
+ * @return Perimeter of given polygon
15
+ */
16
+ public static float perimeter_polygon ( int n , float side ){
17
+ float perimeter = n *side ;
18
+ return perimeter ;
19
+ }
20
+ /**
21
+ *Calculate the Perimeter of rectangle.
22
+ * @parameter length and breadth.
23
+ * @return Perimeter of given rectangle
24
+ */
25
+ public static float perimeter_rectangle ( float length , float breadth ){
26
+ float perimeter = 2 *(length + breadth );
27
+ return perimeter ;
28
+ }
29
+ /**
30
+ *Calculate the circumference of circle.
31
+ * @parameter radius of circle.
32
+ * @return circumference of given circle.
33
+ */
34
+ public static double circumference ( float r ){
35
+ double circumference = 2 *Math .PI *r ;
36
+ return circumference ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ package com .thealgorithms .maths ;
2
+
3
+ import org .junit .jupiter .api .Assertions ;
4
+ import org .junit .jupiter .api .Test ;
5
+
6
+ public class perimeterTest {
7
+
8
+ //Perimeter of polygon
9
+ @ Test
10
+ void testcase1 (){
11
+ Assertions .assertEquals (20.0 ,Perimeter .perimeter_polygon (4 ,5 ));
12
+ }
13
+ @ Test
14
+ void testcase2 (){
15
+ Assertions .assertEquals (30.0 ,Perimeter .perimeter_polygon (5 ,6 ));
16
+ }
17
+
18
+ //Perimeter of Rectangle
19
+ @ Test
20
+ void testcase3 (){
21
+ Assertions .assertEquals (18.0 ,Perimeter .perimeter_rectangle (4 ,5 ));
22
+ }
23
+ @ Test
24
+ void testcase4 (){
25
+ Assertions .assertEquals (14.0 ,Perimeter .perimeter_rectangle (4 ,3 ));
26
+ }
27
+
28
+ //Circumference of a circle
29
+ @ Test
30
+ void testcase5 (){
31
+ Assertions .assertEquals (31.41592653589793 ,Perimeter .circumference (5 ));
32
+ }
33
+ @ Test
34
+ void testcase6 (){
35
+ Assertions .assertEquals (43.982297150257104 ,Perimeter .circumference (7 ));
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments