diff --git a/.github/workflows/maven-workflow.yml b/.github/workflows/maven-workflow.yml
new file mode 100644
index 0000000..3384681
--- /dev/null
+++ b/.github/workflows/maven-workflow.yml
@@ -0,0 +1,26 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: Java CI with Maven
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK 17
+ uses: actions/setup-java@v2
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: maven
+ - name: Build with Maven
+ run: mvn -B package --file pom.xml
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..3384681
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,26 @@
+# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: Java CI with Maven
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK 17
+ uses: actions/setup-java@v2
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: maven
+ - name: Build with Maven
+ run: mvn -B package --file pom.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 9a536f5..e0991c0 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,6 +7,7 @@
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d31b37a..8c1e2b0 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,5 +8,5 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/edu/bristol/IMDBRating.java b/src/main/java/edu/bristol/IMDBRating.java
index 6021d63..20eaadf 100644
--- a/src/main/java/edu/bristol/IMDBRating.java
+++ b/src/main/java/edu/bristol/IMDBRating.java
@@ -6,11 +6,17 @@ public class IMDBRating
private int ratingCount = 0;
public float addNewRating(int newRating)
- {
+ { if(newRating<1){
+ newRating =1;
+ }
+ if(newRating>10){
+ newRating=10;
+ }
int previousTotal = (int) (currentAverage * ratingCount);
int newTotal = previousTotal + newRating;
ratingCount++;
- currentAverage = newTotal / ratingCount;
+ //currentAverage = newTotal / ratingCount;
+ currentAverage = newTotal / (float)ratingCount;
return currentAverage;
}
}
diff --git a/src/test/java/edu/bristol/IMDBRatingTest.java b/src/test/java/edu/bristol/IMDBRatingTest.java
index 76a9e9c..c92def1 100644
--- a/src/test/java/edu/bristol/IMDBRatingTest.java
+++ b/src/test/java/edu/bristol/IMDBRatingTest.java
@@ -1,6 +1,8 @@
package edu.bristol;
import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class IMDBRatingTest
@@ -16,5 +18,31 @@ public void testAverageRating()
averageRating = rater.addNewRating(4);
assertTrue(averageRating == 3.0, "Adding 2nd rating: average should be 3.0");
+
+ averageRating = rater.addNewRating(6);
+ assertTrue(averageRating == 4.0, "Adding 3rd rating: average should be 4.0");
+
+ }
+ @Test
+ public void testAverageRating2()
+ {
+ float averageRating;
+ IMDBRating rater = new IMDBRating();
+
+ averageRating = rater.addNewRating(2);
+ assertEquals( 2.0, averageRating);
+
+ averageRating = rater.addNewRating(3);
+ assertEquals( 2.5, averageRating);
+ //ratings greater than 10 is treated as 10
+ averageRating = rater.addNewRating(16);
+ assertEquals( 5.0, averageRating);
+ //ratings less than 1 is treated as 1
+ averageRating = rater.addNewRating(-12);
+ assertEquals( 4, averageRating);
+
+ averageRating = rater.addNewRating(4);
+ assertEquals( 4.0, averageRating);
}
+
}
diff --git a/target/classes/edu/bristol/IMDBRating.class b/target/classes/edu/bristol/IMDBRating.class
new file mode 100644
index 0000000..f90a3bf
Binary files /dev/null and b/target/classes/edu/bristol/IMDBRating.class differ
diff --git a/target/test-classes/edu/bristol/IMDBRatingTest.class b/target/test-classes/edu/bristol/IMDBRatingTest.class
new file mode 100644
index 0000000..c61d440
Binary files /dev/null and b/target/test-classes/edu/bristol/IMDBRatingTest.class differ