This PR sets up the new integrated test/bench suite. It then migrates all benchmarks and some related tests to the new suite. There's also some documentation and some linting. For now, a lot of the old tests are left alone so this PR doesn't become even larger than it already is. Eventually, all tests should be migrated to the new suite though so there isn't a confusing mix of two systems.
42 lines
1.1 KiB
Text
42 lines
1.1 KiB
Text
module
|
|
|
|
-- Test that termination proofs for stepping through a string with `next` and `prev` works.
|
|
|
|
def isConsonant (i : String.Pos str) : Bool :=
|
|
match i.get! with
|
|
| 'a' | 'e' | 'i' | 'o' | 'u' => false
|
|
| 'y' =>
|
|
if h : i = str.startPos then true
|
|
else !isConsonant (i.prev h)
|
|
| _ => true
|
|
termination_by i.down
|
|
|
|
def measure₁ (word : String) : Nat :=
|
|
let rec aux (pos : String.Pos word) (inVowel : Bool) (count : Nat) : Nat :=
|
|
match h : pos.next? with
|
|
| some next =>
|
|
if !isConsonant pos then
|
|
aux next true count
|
|
else if inVowel then
|
|
aux next false (count + 1)
|
|
else
|
|
aux next false count
|
|
| none => count
|
|
termination_by pos
|
|
|
|
aux word.startPos false 0
|
|
|
|
def measure₂ (word : String) : Nat :=
|
|
let rec aux (pos : String.Pos word) (inVowel : Bool) (count : Nat) : Nat :=
|
|
if h : pos = word.endPos then count
|
|
else
|
|
let next := pos.next h
|
|
if !isConsonant pos then
|
|
aux next true count
|
|
else if inVowel then
|
|
aux next false (count + 1)
|
|
else
|
|
aux next false count
|
|
termination_by pos
|
|
|
|
aux word.startPos false 0
|