File size: 777 Bytes
bcffb9c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
func has_close_element:bool nums:[]num threshold:num
for i := range (len nums)
for j := range (i + 1) (len nums)
if (abs nums[i]-nums[j])<threshold
return true
end
end
end
return false
end
func abs:num n:num
if n < 0
return -n
end
return n
end
fails := 0
total := 0
func assert want:any got:any
total = total + 1
if want != got
fails = fails + 1
printf "want != got: want %v got %v\n" want got
end
end
func finished
printf "%v of %v tests passed\n" (total - fails) total
end
// -- Test Cases Start -- //
assert false (has_close_element [1.0 2.0 3.0] 0.5)
assert true (has_close_element [1.0 2.8 3.0 4.0 5.0 2.0] 0.3)
// -- Test Cases End -- //
finished |