我使用此代码来检查用户的输入(始终为数字)是偶数还是奇数,但脚本始终返回“偶数”
read -p "Enter a number: " x
if ((x % 2 == 0));
then echo "Even";
else echo "Odd";
fi
我正在使用这个测试:
def solution(x)
puts("Number: #{x}")
run_shell(args: [x]).strip
end
describe "Solution" do
it "should print 'Even' for even numbers" do
[0, 2, 4, 78, 100000, 1545452, -2, -10, -123456]
.each { |x| expect(solution(x)).to eq('Even') }
end
it "should print 'Odd' for odd numbers" do
[1, 3, 5, 77, 100001, 1545455, -1, -3, -9, -12345]
.each { |x| expect(solution(x)).to eq('Odd') }
end
end