| @@ -7,7 +7,7 @@ | |||||
| <version>1.0-SNAPSHOT</version> | <version>1.0-SNAPSHOT</version> | ||||
| <name>webssh Maven Webapp</name> | <name>webssh Maven Webapp</name> | ||||
| <url>http://maven.apache.org</url> | <url>http://maven.apache.org</url> | ||||
| <properties> | <properties> | ||||
| <swagger2.version>2.6.1</swagger2.version> | <swagger2.version>2.6.1</swagger2.version> | ||||
| <spring.version>4.3.6.RELEASE</spring.version> | <spring.version>4.3.6.RELEASE</spring.version> | ||||
| @@ -27,7 +27,7 @@ | |||||
| </properties> | </properties> | ||||
| <dependencies> | <dependencies> | ||||
| <dependency> | <dependency> | ||||
| <groupId>org.freemarker</groupId> | <groupId>org.freemarker</groupId> | ||||
| <artifactId>freemarker</artifactId> | <artifactId>freemarker</artifactId> | ||||
| @@ -172,7 +172,7 @@ | |||||
| <artifactId>maven-surefire-plugin</artifactId> | <artifactId>maven-surefire-plugin</artifactId> | ||||
| <version>2.18.1</version> | <version>2.18.1</version> | ||||
| <configuration> | <configuration> | ||||
| <skipTests>true</skipTests> | |||||
| <skipTests>false</skipTests> | |||||
| </configuration> | </configuration> | ||||
| </plugin> | </plugin> | ||||
| @@ -0,0 +1,36 @@ | |||||
| package com.educoder.bridge.service; | |||||
| /** | |||||
| * @Author: youys | |||||
| * @Date: 2023/2/27 | |||||
| * @Description: | |||||
| */ | |||||
| public class CalculatorService { | |||||
| public int add(int a, int b) { | |||||
| return a + b; | |||||
| } | |||||
| public int subtract(int a, int b) { | |||||
| return a - b; | |||||
| } | |||||
| public int multiply(int a, int b) { | |||||
| return a * b; | |||||
| } | |||||
| public double divide(double a, double b) { | |||||
| if (b == 0) { | |||||
| throw new IllegalArgumentException("Cannot divide by zero!"); | |||||
| } | |||||
| return a / b; | |||||
| } | |||||
| public double sqrt(double a) { | |||||
| if (a < 0) { | |||||
| throw new IllegalArgumentException("Cannot calculate square root of negative number!"); | |||||
| } | |||||
| return Math.sqrt(a); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,65 @@ | |||||
| package com.educoder.bridge; | |||||
| import com.educoder.bridge.service.CalculatorService; | |||||
| import org.junit.Test; | |||||
| import static org.junit.Assert.assertEquals; | |||||
| import static org.junit.Assert.fail; | |||||
| /** | |||||
| * @Author: youys | |||||
| * @Date: 2023/2/27 | |||||
| * @Description: | |||||
| */ | |||||
| public class CalculatorServiceTest { | |||||
| @Test | |||||
| public void testAdd() { | |||||
| CalculatorService calculator = new CalculatorService(); | |||||
| int result = calculator.add(1, 2); | |||||
| assertEquals(3, result); | |||||
| } | |||||
| @Test | |||||
| public void testSubtract() { | |||||
| CalculatorService calculator = new CalculatorService(); | |||||
| int result = calculator.subtract(5, 2); | |||||
| assertEquals(3, result); | |||||
| } | |||||
| @Test | |||||
| public void testMultiply() { | |||||
| CalculatorService calculator = new CalculatorService(); | |||||
| int result = calculator.multiply(3, 4); | |||||
| assertEquals(12, result); | |||||
| } | |||||
| @Test | |||||
| public void testDivide() { | |||||
| CalculatorService calculator = new CalculatorService(); | |||||
| double result = calculator.divide(10, 2); | |||||
| assertEquals(5.0, result, 0); | |||||
| try { | |||||
| calculator.divide(10, 0); | |||||
| fail("Expected an IllegalArgumentException to be thrown"); | |||||
| } catch (IllegalArgumentException e) { | |||||
| assertEquals("Cannot divide by zero!", e.getMessage()); | |||||
| } | |||||
| } | |||||
| @Test | |||||
| public void testSqrt() { | |||||
| CalculatorService calculator = new CalculatorService(); | |||||
| double result = calculator.sqrt(16); | |||||
| assertEquals(4.0, result, 0); | |||||
| try { | |||||
| calculator.sqrt(-1); | |||||
| fail("Expected an IllegalArgumentException to be thrown"); | |||||
| } catch (IllegalArgumentException e) { | |||||
| assertEquals("Cannot calculate square root of negative number!", e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,26 @@ | |||||
| package com.educoder.bridge; | |||||
| import org.junit.Test; | |||||
| /** | |||||
| * @Author: youys | |||||
| * @Date: 2023/2/27 | |||||
| * @Description: | |||||
| */ | |||||
| public class MainTest { | |||||
| @Test | |||||
| public void test(){ | |||||
| int a = 1; | |||||
| int b = 0; | |||||
| assert b > 0 : String.format("%s/%s, 除数不能为0",a, b); | |||||
| } | |||||
| @Test | |||||
| public void test2(){ | |||||
| int i=10; | |||||
| assert i > 10 : String.format("变量i=%s,需要大于10", i); | |||||
| } | |||||
| } | |||||