chore: fix tests

This commit is contained in:
Leonardo de Moura 2022-07-09 15:59:44 -07:00
parent e4b358a01e
commit 36ebccb822
6 changed files with 9 additions and 25 deletions

View file

@ -52,6 +52,9 @@ def get : (a : @& ByteArray) → (@& Fin a.size) → UInt8
@[inline] def getOp (self : ByteArray) (idx : Nat) : UInt8 :=
self.get! idx
instance : GetElem ByteArray Nat UInt8 fun xs i => LT.lt i xs.size where
getElem xs i h := xs.get ⟨i, h⟩
@[extern "lean_byte_array_set"]
def set! : ByteArray → (@& Nat) → UInt8 → ByteArray
| ⟨bs⟩, i, b => ⟨bs.set! i b⟩

View file

@ -58,6 +58,9 @@ def get? (ds : FloatArray) (i : Nat) : Option Float :=
@[inline] def getOp (self : FloatArray) (idx : Nat) : Float :=
self.get! idx
instance : GetElem FloatArray Nat Float fun xs i => LT.lt i xs.size where
getElem xs i h := xs.get ⟨i, h⟩
@[extern "lean_float_array_uset"]
def uset : (a : FloatArray) → (i : USize) → Float → i.toNat < a.size → FloatArray
| ⟨ds⟩, i, v, h => ⟨ds.uset i v h⟩

View file

@ -4,7 +4,7 @@
(h : Nat.succ j' < Array.size a),
Array.insertionSort.swapLoop lt a (Nat.succ j') h =
let_fun h' := (_ : j' < Array.size a);
if lt (Array.getOp a { val := Nat.succ j', isLt := h }) (Array.getOp a { val := j', isLt := h' }) = true then
if lt (getElem a (Nat.succ j') h) (getElem a j' h') = true then
Array.insertionSort.swapLoop lt (Array.swap a { val := Nat.succ j', isLt := h } { val := j', isLt := h' }) j'
(_ : j' < Array.size (Array.swap a { val := Nat.succ j', isLt := h } { val := j', isLt := h' }))
else a

View file

@ -366,7 +366,7 @@ def State.step : State → State
| s@(done ..) => s
def Context.equiv (cₗ cᵣ : Context) : Prop :=
∀ n, cₗ[n] = cᵣ[n]
∀ n : String, cₗ[n] = cᵣ[n]
def State.stepN : State → Nat → State
| s, 0 => s

View file

@ -1,22 +0,0 @@
def MyArray := Array
namespace MyArray
def getOp? (self : MyArray α) (idx : Nat) : Option α :=
Array.get? self idx
def getOp! [Inhabited α] (self : MyArray α) (idx : Nat) : α :=
Array.get! self idx
def getOp (self : MyArray α) (idx : Fin self.size) : α :=
Array.get self idx
end MyArray
variable (a : MyArray Nat)
#check a[0]!
#check a[0]?
variable (i : Fin a.size)
#check a[i]

View file

@ -26,7 +26,7 @@ def tst3 (n : Nat) (expected : UInt32) : IO Unit := do
let bs := mkByteArray n
let mut sum := 0
for i in [:bs.size] do
sum := sum + bs[i].toUInt32
sum := sum + bs[i]!.toUInt32
assert! sum == expected
IO.println sum