diff --git a/src/DataTypes.java b/src/DataTypes.java index 4f807c1f..f831f96f 100644 --- a/src/DataTypes.java +++ b/src/DataTypes.java @@ -1,14 +1,18 @@ +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class DataTypes { - // TODO TASK 1: fix this code so that it passes the test in DataTypesTest.java + public static long sum(List numbers) { - int s = 0; + long s = 0; // below is a "foreach" loop which iterates through numbers for (int x : numbers) { s += x; } return s; + } } + diff --git a/test/DataTypesTest.java b/test/DataTypesTest.java index e53951fe..03c395ea 100644 --- a/test/DataTypesTest.java +++ b/test/DataTypesTest.java @@ -24,6 +24,6 @@ public void largeSumTest() { for (int i = 1; i <= 1_000_000; i++) { lst.add(i); } - assertEquals("sum form 1 to 1 million should be " + x, x, DataTypes.sum(lst)); + assertEquals("sum from 1 to 1 million should be " + x, x, DataTypes.sum(lst)); } } \ No newline at end of file