"when input is negative number" $ it "should be same number" $ subject "-1" ‘shouldBe‘ Right (-1) context "when input is rational number" $ it "should be same number" $ subject "0.0123" ‘shouldBe‘ Right (123 % 10000) it "return same float number" $ property propParseRationalNumber RSpec Ͱ͓ೃછΈͷ describe context Ͱจ຺͝ͱʹॻ͖͚Δ͜ͱ͕Ͱ͖ɺshouldBe ؔ ΛͬͯΞαʔγϣϯΛ͍ͯ͠·͢ɻshouldBe ͕ؔதஔԋࢉࢠͷΑ͏ʹஔͰ͖͍ͯΔͷɺ Haskell ͕ҙͷؔΛόοΫΫΦʔτ ‘ ͰғΉ͜ͱͰɺதஔԋࢉࢠͱͯ͠ར༻Ͱ͖Δ͔ΒͰ͢ɻ͋ ࣦ͑ͯഊ͢ΔΑ͏ʹগ͠ॻ͖͑ͯɺ࣮ߦ͢Δͱ࣍ͷΑ͏ʹͳΓ·͢*7ɻ Lib.rationalParser when input is 0 should be same number [o] when input is positive number should be same number [o] when input is negative number should be same number [o] when input is rational number should be same number [x] return same float number [x] Failures: test/hspec/Spec.hs:30:26: 1) Lib.rationalParser, when input is rational number, should be same number expected: Right (123 % 1000) but got: Right (123 % 10000) To rerun use: --match "/Lib.rationalParser/when input is rational number/should beˠ same number/" --seed 629150678 test/hspec/Spec.hs:32:5: 2) Lib.rationalParser return same float number Falsified (after 8 tests and 2 shrinks): 1 % 3 To rerun use: --match "/Lib.rationalParser/return same float number/" --seed 62915ˠ 0678 *7 νΣοΫϚʔΫΛඳࣸͰ͖ͳ͔ͬͨͷͰ o ͱ x ʹஔ͖͍͑ͯ·͢ɻ 18
QuickCheck)" [ testProperty "calculate (show n) == Right n" $ \n -> (calculate $ show’ n) == Right n , testProperty "calculate (show n ++ ’+’ ++ show m) == Right (n + m)" $ \(n, m) -> calculate (show’ n ++ "+" ++ show’ m) == Right (n + m) , testProperty "calculate (show n ++ ’-’ ++ show m) == Right (n - m)" $ \(n, m) -> calculate (show’ n ++ "-" ++ show’ m) == Right (n - m) , testProperty "calculate (show n ++ ’*’ ++ show m) == Right (n * m)" $ \(n, m) -> calculate (show’ n ++ "*" ++ show’ m) == Right (n * m) , testProperty "calculate (show n ++ ’/’ ++ show m) == Right (n / m)" $ \(n, m) -> if m /= 0 then calculate (show’ n ++ "/" ++ show’ m) == Right (n / m) else -- θϩআࢉΤϥʔʹͳΔͨΊεΩοϓ͢Δ True ] where show’ :: Rational -> String show’ n = "(" ++ show (numerator n) ++ "/" ++ show (denominator n) ++ ")" جຊతʹࠓ·ͰͷςετͱมΘΓ·ͤΜɻϢχοτςετʹԋࢉࢠͷ༏ઌॱҐʹؔ͢Δςετ ΛՃ͠ɺϓϩύςΟϕʔεςετʹ࢛ଇԋࢉʹؔ͢ΔςετΛՃ͠·ͨ͠ɻ·ͨɺআࢉ͕͑Δ ʢ࣮࣭ɺ͕ॻ͚ΔʣΑ͏ʹͳͬͨͷͰɺDouble ܕͷͷΘΓʹ Rational ܕͷͰϓϩ ύςΟϕʔεςετΛߦ͍ͬͯ·͢ɻࣦ͋͑ͯഊ͢ΔΑ͏ʹগ͠ॻ͖͑ͯɺ࣮ߦ͢Δͱ࣍ͷΑ͏ʹ ͳΓ·͢ɻ Tests Unit tests zero: OK positive number: OK negative number: OK fraction number: OK precedence of operators: FAIL test/tasty/Spec.hs:23: expected: Right ((-2) % 1) but got: Right ((-1) % 1) Use -p ’/precedence of operators/’ to rerun this test only. Properties (checked by QuickCheck) calculate (show n) == Right n: OK +++ OK, passed 100 tests. calculate (show n ++ ’+’ ++ show m) == Right (n + m): OK +++ OK, passed 100 tests. calculate (show n ++ ’-’ ++ show m) == Right (n - m): OK +++ OK, passed 100 tests. calculate (show n ++ ’*’ ++ show m) == Right (n * m): OK +++ OK, passed 100 tests. calculate (show n ++ ’/’ ++ show m) == Right (n / m): FAIL *** Failed! Exception: ’Ratio has zero denominator’ (after 1 test): 21
% 1) Use --quickcheck-replay=230587 to reproduce. Use -p ’/calculate (show n ++ ’\’’\/’\’’ ++ show m) == Right (n \/ m)/’ to rerˠ un this test only. 2 out of 10 tests failed (0.01s) 2.7 ͓͠·͍ Haskell ͷςετϥΠϒϥϦ΄͔ʹ SmallCheck Hedgehog ͳͲɺओʹϓϩύςΟϕʔε ςετͷϥΠϒϥϦ͕ͨ͘͞Μ͋Γ·͢ɻtasty ͷ README ʹϓϩόΠμͱͯ͠ࡌ͍ͬͯΔͷͰɺ ڵຯ͕͋ΔਓݟʹߦͬͯΈ͍ͯͩ͘͞ɻ͋ͱͪͳΈʹɺࣗ tasty Λ͍ͬͯ·͢ɻ 22