Skip to content

Commit

Permalink
Test case for issue #662
Browse files Browse the repository at this point in the history
  • Loading branch information
robdockins committed Apr 2, 2020
1 parent 4c6424c commit d08046d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/issues/issue662.cry
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type Q = (Integer, Integer)

toQ : Integer -> Integer -> Q
toQ a b =
if b == 0 then error "divide by 0" else
if b < 0 then (negate a, negate b) else (a, b)

leQ : Q -> Q -> Bit
leQ (a,b) (c,d) = a*d <= b*c

intToQ : Integer -> Q
intToQ x = (x, 1)

abs : Integer -> Integer
abs x = if x < 0 then negate x else x

property divRoundsDown (x : Integer) (y : Integer) =
y == 0 \/ leQ (intToQ ( x / y )) (toQ x y)

property divEuclidean (x : Integer) (y : Integer) =
y == 0 \/ y * (x / y) + x % y == x

property modAbs (x : Integer) (y : Integer) =
y == 0 \/ abs (x % y) < abs y
7 changes: 7 additions & 0 deletions tests/issues/issue662.icry
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:l issue662.cry

:set tests=1000
:check

:set prover=z3
:prove
15 changes: 15 additions & 0 deletions tests/issues/issue662.icry.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Loading module Cryptol
Loading module Cryptol
Loading module Main
property divRoundsDown Using random testing.
Testing... Passed 1000 tests.
property divEuclidean Using random testing.
Testing... Passed 1000 tests.
property modAbs Using random testing.
Testing... Passed 1000 tests.
:prove divRoundsDown
Q.E.D.
:prove divEuclidean
Q.E.D.
:prove modAbs
Q.E.D.

0 comments on commit d08046d

Please sign in to comment.