New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add complete queue property checks #1171
Conversation
test_workspace/Nat.bosatsu
Outdated
case Zero: acc | ||
case Succ(n): | ||
# (n + 1) / 2 = n/2 if n is even, else n/2 + 1 | ||
if is_even(n): loop(n, acc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we know that every other item is even. This algorithm is quadratic, but we can make it O(N).
@@ -48,7 +50,7 @@ def fold_Queue(Queue(f, b): Queue[a], init: b, fold_fn: (b, a) -> b) -> b: | |||
b.reverse().foldLeft(front, fold_fn) | |||
|
|||
def reverse_Queue(Queue(f, b): Queue[a]) -> Queue[a]: | |||
Queue(b.reverse(), f.reverse()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this bug was detected by property checks! Yay!
rev_rand = smaller.map_Rand(reverse_Queue) | ||
one_of(pop_rand, [push_rand, rev_rand]) | ||
|
||
rand_Queue_Int: Rand[Queue[Int]] = rand_Queue_depth(int_to_Nat(50)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is building a pretty giant tree perhaps... definitely the checks take a while to run.
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1171 +/- ##
==========================================
+ Coverage 91.32% 91.48% +0.16%
==========================================
Files 96 96
Lines 11846 12010 +164
Branches 2675 2778 +103
==========================================
+ Hits 10818 10987 +169
+ Misses 1028 1023 -5 ☔ View full report in Codecov by Sentry. |
trying to exercise property checks by adding more checks for Queue. Definitely it can be tricky to implement functions in Bosatsu due to the totality requirements. For instance, implementing Rand::one_of was a bit tricky. You have to find the right recursion strategy. I was trying to make sampling O(log N), so I needed to make a tree. To do that, I used BinNat to be able to recur on half the size of the items, rather than the naive approach.
I also found a nice trick.
Define:
then we can consume args and magically produce things by doing
todo((foo, bar))
and runtype-check
. Then it fails at runtime since we don't actually implement todo. We could use this strategy except possibly make that function only exist in predef when running type-check (which doesn't output anything).