Skip to content
Open
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
26 changes: 26 additions & 0 deletions .github/workflows/maven-workflow.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/main/java/edu/bristol/IMDBRating.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
28 changes: 28 additions & 0 deletions src/test/java/edu/bristol/IMDBRatingTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}

}
Binary file added target/classes/edu/bristol/IMDBRating.class
Binary file not shown.
Binary file not shown.