Why does my Exercism task fail?
- Posted by axtens_bruce Feb 13, 2023
- 740 views
Code
public function square(integer n if n < 1 or n > 64 then return "square must be between 1 and 64" end if return power(2, (n-1)) end function public function total() atom sum = 0 for i = 1 to 64 do sum += square(i) end for return sum end function
Tests
include std/unittest.e include grains.ex test_equal("grains on square 1",square(1),1) test_equal("grains on square 2",square(2),2) test_equal("grains on square 3",square(3),4) test_equal("grains on square 4",square(4),8) test_equal("grains on square 16",square(16),32768) test_equal("grains on square 32",square(32),2147483648) test_equal("grains on square 64",square(64),9223372036854775808) test_equal("square 0 raises an exception",square(0),"square must be between 1 and 64") test_equal("negative square raises an exception",square(-1),"square must be between 1 and 64") test_equal("square greater than 64 raises an exception",square(65),"square must be between 1 and 64") test_equal("returns the total number of grains on the board", total(), 18446744073709551615) test_report()
Run, failing on test test_equal("grains on square 64",square(64),9223372036854775808)
>eutest interpreting t_grains.e: failed: grains on square 64, expected: 9.22337203685478e+018 but got: -9.22337203685478e+018 11 tests run, 10 passed, 1 failed, 91% success FAILURE: t_grains.e program died with status 1 Test results summary: FAIL: t_grains.e Files (run: 1) (failed: 1) (0% success)