From f3e7c34c0a9337d041a18d143485f14ed8f22bed Mon Sep 17 00:00:00 2001 From: XLanLi Date: Wed, 23 Feb 2022 23:26:23 +0000 Subject: [PATCH 1/6] test1 --- src/main/java/edu/bristol/IMDBRating.java | 4 ++-- src/test/java/edu/bristol/IMDBRatingTest.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/bristol/IMDBRating.java b/src/main/java/edu/bristol/IMDBRating.java index 6021d63..1d4686b 100644 --- a/src/main/java/edu/bristol/IMDBRating.java +++ b/src/main/java/edu/bristol/IMDBRating.java @@ -7,8 +7,8 @@ public class IMDBRating public float addNewRating(int newRating) { - int previousTotal = (int) (currentAverage * ratingCount); - int newTotal = previousTotal + newRating; + float previousTotal = (float) (currentAverage * ratingCount); + float newTotal = previousTotal + newRating; ratingCount++; currentAverage = newTotal / ratingCount; return currentAverage; diff --git a/src/test/java/edu/bristol/IMDBRatingTest.java b/src/test/java/edu/bristol/IMDBRatingTest.java index 76a9e9c..bd2cf43 100644 --- a/src/test/java/edu/bristol/IMDBRatingTest.java +++ b/src/test/java/edu/bristol/IMDBRatingTest.java @@ -16,5 +16,19 @@ public void testAverageRating() averageRating = rater.addNewRating(4); assertTrue(averageRating == 3.0, "Adding 2nd rating: average should be 3.0"); + + } + @Test + public void testAverageRating2() + { + float averageRating; + IMDBRating rater = new IMDBRating(); + + averageRating = rater.addNewRating(1); + assertTrue(averageRating == 1.0, "Adding 1st rating: average should be 1.0"); + + averageRating = rater.addNewRating(2); + assertTrue(averageRating == 1.5, "Adding 2nd rating: average should be 1.5"); + } } From 5692b9569e700df9e2970b90ecd2f817edb01480 Mon Sep 17 00:00:00 2001 From: XLanLi Date: Wed, 23 Feb 2022 23:33:30 +0000 Subject: [PATCH 2/6] changes 11 --- .idea/compiler.xml | 1 + .idea/misc.xml | 2 +- target/classes/edu/bristol/IMDBRating.class | Bin 0 -> 577 bytes .../edu/bristol/IMDBRatingTest.class | Bin 0 -> 1196 bytes 4 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 target/classes/edu/bristol/IMDBRating.class create mode 100644 target/test-classes/edu/bristol/IMDBRatingTest.class 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..67e1e61 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,5 +8,5 @@ - + \ No newline at end of file diff --git a/target/classes/edu/bristol/IMDBRating.class b/target/classes/edu/bristol/IMDBRating.class new file mode 100644 index 0000000000000000000000000000000000000000..381d3c91e41b5f1a9b58421b9ef056b89f045cb5 GIT binary patch literal 577 zcmZuuT}vB56g_u$YfQ39tk#dJr3ekgeQ16_wP4jiAhpnn&^Kq3A)T=9%49db`{2(h z2uh(3{Q><^#WQQfmojkYo;&B>bMKwM|9<}gu#Y!2cUes+*{E-2D#ij)e{7X*jdh_u$gr23?|h_yXcal***ARDUWOj+abJQ(CZ z%v7*3_`m)KL8wNf6Mgm6PtfV__5{`RIn=ncdSdYa`b5iIg;?$*9#g&pdiaSgPd z=X&q9gB=dyaeE#Qw@`YVs=URm5rUUQ2YeUat>_mds^6m$`S)ntmc(V+CVW~S0h6js zTOkS`Q}7C_MBFge=jEl`R}j4-+uylf(J=N5Y?fj5JQ|{AwvHlOctU)rrCbVOCSo>8dAzQHEUAvgo8y@_fVXG+8(Jsc?Bq7~Y{1v@N3{jB=rv z#2ChP+(=;plMIIAw#=h|xG0`TU$`bek!IENgzHPk_85}9lN`8#AmZHXS~%Ih?~>?7 zz8etO-4|I1k6kTNDm>J&$S`y9O&6x9i-MD(`J-{-LC6$<{7!xxp~%Q|oHifxd4;JxBUE z+hT~3Tf$|Sx}+Vo8rt`H^UV%F=>bgd1-37bMO}K5u&TE0_+)vYQjI(oeunByL79yO+@h~rJy8%c;uLRFX41-NjV+yleW5=Q+@Yw-D&D1- z>b`(`$Wg|Sr~OFh@F!^04%qks{nZ(+?X1MUBDuNvZXD_NAE0ZWp+z$z-;i0+`-Q2n zFhd0;8SO~UP+KLIK$?ETL_A888LVTxgJE=~dKhWk#}bwaCxKP0P!>Uf&ZnXM!E8i_ zUSX3JM)P%tDbmVN8lZpdp|1_lwJzas$d^^%gNf$Cf^h-(G=a>Ld=~SVqk-n}h(=KN Y*9Bi2fG-cgOaFsUUj|;LJ`t?`1MB<%ivR!s literal 0 HcmV?d00001 From b7379069c2f55e38be23649d7b24d3862c3ec6e4 Mon Sep 17 00:00:00 2001 From: XLanLi Date: Wed, 23 Feb 2022 23:37:02 +0000 Subject: [PATCH 3/6] other out of range --- src/main/java/edu/bristol/IMDBRating.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/edu/bristol/IMDBRating.java b/src/main/java/edu/bristol/IMDBRating.java index 1d4686b..d3dbfa3 100644 --- a/src/main/java/edu/bristol/IMDBRating.java +++ b/src/main/java/edu/bristol/IMDBRating.java @@ -7,6 +7,9 @@ public class IMDBRating public float addNewRating(int newRating) { + if(newRating>10 || newRating<0) { + return currentAverage; + } float previousTotal = (float) (currentAverage * ratingCount); float newTotal = previousTotal + newRating; ratingCount++; From 42fe06bd9f7cc49bd4c4e456ee673299ff4b37ce Mon Sep 17 00:00:00 2001 From: XLanLi <98281893+XLanLi@users.noreply.github.com> Date: Thu, 24 Feb 2022 00:11:10 +0000 Subject: [PATCH 4/6] Create maven.yml --- .github/workflows/maven.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..2566386 --- /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 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml From 95259e6f9054fc347b68158200b55e47d50d1f3d Mon Sep 17 00:00:00 2001 From: XLanLi <98281893+XLanLi@users.noreply.github.com> Date: Thu, 24 Feb 2022 00:17:59 +0000 Subject: [PATCH 5/6] Update maven.yml --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2566386..3384681 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'temurin' cache: maven - name: Build with Maven From 634e5f966714842c6a1d1f716d95a71f5aec6ac2 Mon Sep 17 00:00:00 2001 From: XLanLi Date: Thu, 24 Feb 2022 00:21:33 +0000 Subject: [PATCH 6/6] test 2 --- src/test/java/edu/bristol/IMDBRatingTest.java | 16 ++++++++++++++++ target/classes/edu/bristol/IMDBRating.class | Bin 577 -> 626 bytes .../edu/bristol/IMDBRatingTest.class | Bin 1196 -> 1452 bytes 3 files changed, 16 insertions(+) diff --git a/src/test/java/edu/bristol/IMDBRatingTest.java b/src/test/java/edu/bristol/IMDBRatingTest.java index bd2cf43..7ab0e92 100644 --- a/src/test/java/edu/bristol/IMDBRatingTest.java +++ b/src/test/java/edu/bristol/IMDBRatingTest.java @@ -31,4 +31,20 @@ public void testAverageRating2() assertTrue(averageRating == 1.5, "Adding 2nd rating: average should be 1.5"); } + @Test + public void testAverageRating3() + { + float averageRating; + IMDBRating rater = new IMDBRating(); + + averageRating = rater.addNewRating(2); + assertTrue(averageRating == 2.0); + + averageRating = rater.addNewRating(11); + assertTrue(averageRating == 2.0); + + averageRating = rater.addNewRating(-1); + assertTrue(averageRating == 2.0); + + } } diff --git a/target/classes/edu/bristol/IMDBRating.class b/target/classes/edu/bristol/IMDBRating.class index 381d3c91e41b5f1a9b58421b9ef056b89f045cb5..d7ac85a5d19f1102274eec205eb0c5496878aeb6 100644 GIT binary patch delta 173 zcmX@e@`;7()W2Q(7#J9A8RRx{i8Au>2A3ozXZt1=gd`^Aq)wJ)oG!7Lfti5?sKioQ zfNL=WyYw6e4y`Q=?CU1)Wz@}NW)K2O$uY14NiHDdX5eSwWsqXvV~_{3G#LaKOc(?i zgn_bJ5JMP57({_Qpm7WmKv_nhT6qRZ1|9|`AT0%iJV5KDf$}U2Ok6BLc^M#^i9r?s DAr=-N delta 125 zcmeywa*&1V)W2Q(7#J9A8Duwdi84;sXPnB}#K6qJ0u!aEQKJ5%IFZ(&4Wmn4kcYZb?guxqW*y{ zUL?>csOZ?g)4Awv+6rY1yl-Z{H}9MG>aM!mc>8>K0+2(gjG9Nf(4s30fo5IVR@9CwtHzm-S-Q(kNcYJO9__6~ZM4uCxKPN{1q_#woMEVO@E<$wx delta 294 zcmY+8OHKk&5JgYDN7M32Pl%94!cW?kj~|4A#uynJ*T5E7i|LVTfC*vdfCVse9nM&Q zgnBKIIJv1?IdyL>3X5ERv-?^DFN~M@Ps#dR3e}I-^6FbWNq$VH)W#?P7QrK{+DTfr z97noy&gqqEF`YePuGI-$-5X`6_FbZ6ZX2byXWg`6V Jd{DwL+5?|(9Do1-