Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cache: maven

- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn -B package --file my-app/pom.xml

- name: Run the Maven verify phase
run: mvn --batch-mode --update-snapshots verify
run: mvn --batch-mode --update-snapshots verify --file my-app/pom.xml
96 changes: 96 additions & 0 deletions my-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>

<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- Optionally: parameterized tests support -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
15 changes: 15 additions & 0 deletions my-app/src/main/java/com/mycompany/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mycompany.app;

/**
* Hello world!
*/
public class App
{
public static void main(String[] args)
{
double val=Double.parseDouble("2.0");
Sqrt sqrt=new Sqrt(val);
double result=sqrt.calc();
System.out.println("Sqrt of " + val + " = " + result);
}
}
29 changes: 29 additions & 0 deletions my-app/src/main/java/com/mycompany/app/Sqrt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mycompany.app;

public class Sqrt
{
double delta=0.00000001;
double arg;

public Sqrt(double arg) {
this.arg=arg;
}
public double average(double x,double y) {
return (x+y)/2.0;
}
public boolean good(double guess,double x) {
return Math.abs(guess*guess-x)<delta;
}
public double improve(double guess,double x) {
return average(guess,x/guess);
}
public double iter(double guess, double x) {
if(good(guess,x))
return guess;
else
return iter(improve(guess,x),x);
}
public double calc() {
return iter(1.0,arg);
}
}
109 changes: 109 additions & 0 deletions my-app/src/test/java/com/mycompany/app/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.mycompany.app;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

/**
* Unit test for simple App.
*/
public class AppTest {

/**
* Rigorous Test :-)
*/
private static final double DELTA = 1e-6;

@Test
public void testSqrtOf4() {
Sqrt sqrt = new Sqrt(4.0);
assertEquals(2.0, sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf9() {
Sqrt sqrt = new Sqrt(9.0);
assertEquals(3.0, sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf16() {
Sqrt sqrt = new Sqrt(16.0);
assertEquals(4.0, sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf2() {
Sqrt sqrt = new Sqrt(2.0);
assertEquals(Math.sqrt(2.0), sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf0() {
Sqrt sqrt = new Sqrt(0.0);
double result = sqrt.calc();
assertTrue(result < 1e-4);
}

@Test
public void testSqrtOf1() {
Sqrt sqrt = new Sqrt(1.0);
assertEquals(1.0, sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf0_25() {
Sqrt sqrt = new Sqrt(0.25);
assertEquals(0.5, sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf100() {
Sqrt sqrt = new Sqrt(100.0);
assertEquals(10.0, sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf0_01() {
Sqrt sqrt = new Sqrt(0.01);
assertEquals(0.1, sqrt.calc(), DELTA);
}

@Test
public void testSqrtOf144() {
Sqrt sqrt = new Sqrt(144.0);
assertEquals(12.0, sqrt.calc(), DELTA);
}

@Test
public void testAverage() {
Sqrt sqrt = new Sqrt(4.0);
assertEquals(6.5, sqrt.average(4.0, 9.0), DELTA);
}

@Test
public void testGoodReturnsTrue() {
Sqrt sqrt = new Sqrt(4.0);
assertTrue(sqrt.good(2.0, 4.0));
}

@Test
public void testGoodReturnsFalse() {
Sqrt sqrt = new Sqrt(4.0);
assertFalse(sqrt.good(3.0, 4.0));
}

@Test
public void testImprove() {
Sqrt sqrt = new Sqrt(4.0);
assertEquals(2.1666666666666665, sqrt.improve(3.0, 4.0), DELTA);
}

@Test
public void testSqrtOf1000000() {
Sqrt sqrt = new Sqrt(1000000.0);
assertEquals(1000.0, sqrt.calc(), DELTA);
}
}
Loading