chore: write tests for the non-verified tree map functions (#7680)

This PR provides tests for those tree map functions that are not
verified yet.

---------

Co-authored-by: Paul Reichert <datokrat@users.noreply.github.com>
This commit is contained in:
Paul Reichert 2025-03-27 14:52:34 +01:00 committed by GitHub
parent e46cc64d1e
commit 7bd9375804
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 2008 additions and 53 deletions

View file

@ -419,37 +419,61 @@ def maxKeyD (t : DTreeMap α β cmp) (fallback : α) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.maxKeyD fallback
/-- Returns the key-value pair with the `n`-th smallest key, or `none` if `n` is at least `t.size`. -/
@[inline]
def entryAtIdx? (t : DTreeMap α β cmp) (n : Nat) : Option ((a : α) × β a) :=
letI : Ord α := ⟨cmp⟩; t.inner.entryAtIdx? n
/-- Returns the key-value pair with the `n`-th smallest key. -/
@[inline]
def entryAtIdx (t : DTreeMap α β cmp) (n : Nat) (h : n < t.size) : (a : α) × β a :=
letI : Ord α := ⟨cmp⟩; Impl.entryAtIdx t.inner t.wf.balanced n h
/-- Returns the key-value pair with the `n`-th smallest key, or panics if `n` is at least `t.size`. -/
@[inline]
def entryAtIdx! [Inhabited ((a : α) × β a)] (t : DTreeMap α β cmp) (n : Nat) : (a : α) × β a :=
letI : Ord α := ⟨cmp⟩; t.inner.entryAtIdx! n
/-- Returns the key-value pair with the `n`-th smallest key, or `fallback` if `n` is at least `t.size`. -/
@[inline]
def entryAtIdxD (t : DTreeMap α β cmp) (n : Nat)
(fallback : (a : α) × β a) : (a : α) × β a :=
letI : Ord α := ⟨cmp⟩; t.inner.entryAtIdxD n fallback
/-- Returns the `n`-th smallest key, or `none` if `n` is at least `t.size`. -/
@[inline]
def keyAtIdx? (t : DTreeMap α β cmp) (n : Nat) : Option α :=
letI : Ord α := ⟨cmp⟩; Impl.keyAtIdx? t.inner n
@[inline, inherit_doc keyAtIdx?, deprecated keyAtIdx? (since := "2025-03-25")]
def keyAtIndex? (t : DTreeMap α β cmp) (n : Nat) : Option α :=
letI : Ord α := ⟨cmp⟩; Impl.keyAtIndex? t.inner n
keyAtIdx? t n
/-- Returns the `n`-th smallest key. -/
@[inline]
def keyAtIdx (t : DTreeMap α β cmp) (n : Nat) (h : n < t.size) : α :=
letI : Ord α := ⟨cmp⟩; Impl.keyAtIdx t.inner t.wf.balanced n h
@[inline, inherit_doc keyAtIdx, deprecated keyAtIdx (since := "2025-03-25")]
def keyAtIndex (t : DTreeMap α β cmp) (n : Nat) (h : n < t.size) : α :=
letI : Ord α := ⟨cmp⟩; Impl.keyAtIndex t.inner t.wf.balanced n h
keyAtIdx t n h
/-- Returns the `n`-th smallest key, or panics if `n` is at least `t.size`. -/
@[inline]
def keyAtIdx! [Inhabited α] (t : DTreeMap α β cmp) (n : Nat) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIdx! n
@[inline, inherit_doc keyAtIdx!, deprecated keyAtIdx! (since := "2025-03-25")]
def keyAtIndex! [Inhabited α] (t : DTreeMap α β cmp) (n : Nat) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIndex! n
keyAtIdx! t n
/-- Returns the `n`-th smallest key, or `fallback` if `n` is at least `t.size`. -/
@[inline]
def keyAtIdxD (t : DTreeMap α β cmp) (n : Nat) (fallback : α) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIdxD n fallback
@[inline, inherit_doc keyAtIdxD, deprecated keyAtIdxD (since := "2025-03-25")]
def keyAtIndexD (t : DTreeMap α β cmp) (n : Nat) (fallback : α) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIndexD n fallback
keyAtIdxD t n fallback
/--
Tries to retrieve the key-value pair with the smallest key that is greater than or equal to the
@ -1114,7 +1138,7 @@ def insertManyIfNewUnit {ρ} [ForIn Id ρ α] (t : DTreeMap α Unit cmp) (l : ρ
end Const
instance [Repr α] [(a : α) → Repr (β a)] : Repr (DTreeMap α β cmp) where
reprPrec m prec := Repr.addAppParen ("DTreeMap.ofList " ++ repr m.toList) prec
reprPrec m prec := Repr.addAppParen ("Std.DTreeMap.ofList " ++ repr m.toList) prec
end DTreeMap

View file

@ -406,40 +406,40 @@ def entryAtIdxD : Impl α β → Nat → (a : α) × β a → (a : α) × β a
| .gt => r.entryAtIdxD (n - l.size - 1) fallback
/-- Implementation detail of the tree map -/
def keyAtIndex : (t : Impl α β) → (hl : t.Balanced) → (n : Nat) → (h : n < t.size) → α
def keyAtIdx : (t : Impl α β) → (hl : t.Balanced) → (n : Nat) → (h : n < t.size) → α
| .inner _ k _ l' r', hl, n, h =>
match h : compare n l'.size with
| .lt => keyAtIndex l' hl.left n (by simpa only [Std.Internal.tree_tac] using h)
| .lt => keyAtIdx l' hl.left n (by simpa only [Std.Internal.tree_tac] using h)
| .eq => k
| .gt =>
keyAtIndex r' hl.right (n - l'.size - 1) (by simp_all only [Std.Internal.tree_tac]; omega)
keyAtIdx r' hl.right (n - l'.size - 1) (by simp_all only [Std.Internal.tree_tac]; omega)
/-- Implementation detail of the tree map -/
def keyAtIndex? : Impl α β → Nat → Option α
def keyAtIdx? : Impl α β → Nat → Option α
| .leaf, _ => none
| .inner _ k _ l r, n =>
match compare n l.size with
| .lt => keyAtIndex? l n
| .lt => keyAtIdx? l n
| .eq => some k
| .gt => keyAtIndex? r (n - l.size - 1)
| .gt => keyAtIdx? r (n - l.size - 1)
/-- Implementation detail of the tree map -/
def keyAtIndex! [Inhabited α] : Impl α β → Nat → α
def keyAtIdx! [Inhabited α] : Impl α β → Nat → α
| .leaf, _ => panic! "Out-of-bounds access"
| .inner _ k _ l r, n =>
match compare n l.size with
| .lt => keyAtIndex! l n
| .lt => keyAtIdx! l n
| .eq => k
| .gt => keyAtIndex! r (n - l.size - 1)
| .gt => keyAtIdx! r (n - l.size - 1)
/-- Implementation detail of the tree map -/
def keyAtIndexD : Impl α β → Nat → αα
def keyAtIdxD : Impl α β → Nat → αα
| .leaf, _, fallback => fallback
| .inner _ k _ l r, n, fallback =>
match compare n l.size with
| .lt => keyAtIndexD l n fallback
| .lt => keyAtIdxD l n fallback
| .eq => k
| .gt => keyAtIndexD r (n - l.size - 1) fallback
| .gt => keyAtIdxD r (n - l.size - 1) fallback
/-- Implementation detail of the tree map -/
@[inline]

View file

@ -303,21 +303,33 @@ def entryAtIdx! [Inhabited ((a : α) × β a)] (t : Raw α β cmp) (n : Nat) : (
def entryAtIdxD (t : Raw α β cmp) (n : Nat) (fallback : (a : α) × β a) : (a : α) × β a :=
letI : Ord α := ⟨cmp⟩; t.inner.entryAtIdxD n fallback
@[inline, inherit_doc DTreeMap.keyAtIndex?]
@[inline, inherit_doc DTreeMap.keyAtIdx?]
def keyAtIdx? (t : Raw α β cmp) (n : Nat) : Option α :=
letI : Ord α := ⟨cmp⟩; Impl.keyAtIdx? t.inner n
@[inline, inherit_doc DTreeMap.keyAtIdx?, deprecated keyAtIdx? (since := "2025-03-25")]
def keyAtIndex? (t : Raw α β cmp) (n : Nat) : Option α :=
letI : Ord α := ⟨cmp⟩; Impl.keyAtIndex? t.inner n
keyAtIdx? t n
/-!
We do not provide `keyAtIndex` for the raw trees.
We do not provide `keyAtIdx` for the raw trees.
-/
@[inline, inherit_doc DTreeMap.keyAtIndex!]
def keyAtIndex! [Inhabited α] (t : Raw α β cmp) (n : Nat) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIndex! n
@[inline, inherit_doc DTreeMap.keyAtIdx!]
def keyAtIdx! [Inhabited α] (t : Raw α β cmp) (n : Nat) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIdx! n
@[inline, inherit_doc DTreeMap.keyAtIndexD]
@[inline, inherit_doc DTreeMap.keyAtIdx!, deprecated keyAtIdx! (since := "2025-03-25")]
def keyAtIndex! [Inhabited α] (t : Raw α β cmp) (n : Nat) : α :=
keyAtIdx! t n
@[inline, inherit_doc DTreeMap.keyAtIdxD]
def keyAtIdxD (t : Raw α β cmp) (n : Nat) (fallback : α) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIdxD n fallback
@[inline, inherit_doc DTreeMap.keyAtIdxD, deprecated keyAtIdxD (since := "2025-03-25")]
def keyAtIndexD (t : Raw α β cmp) (n : Nat) (fallback : α) : α :=
letI : Ord α := ⟨cmp⟩; t.inner.keyAtIndexD n fallback
keyAtIdxD t n fallback
@[inline, inherit_doc DTreeMap.getEntryGE?]
def getEntryGE? (t : Raw α β cmp) (k : α) : Option ((a : α) × β a) :=
@ -805,7 +817,7 @@ def insertManyIfNewUnit {ρ} [ForIn Id ρ α] (t : Raw α Unit cmp) (l : ρ) : R
end Const
instance [Repr α] [(a : α) → Repr (β a)] : Repr (Raw α β cmp) where
reprPrec m prec := Repr.addAppParen ("DTreeMap.Raw.ofList " ++ repr m.toList) prec
reprPrec m prec := Repr.addAppParen ("Std.DTreeMap.Raw.ofList " ++ repr m.toList) prec
end Raw

View file

@ -292,21 +292,37 @@ def entryAtIdx! [Inhabited (α × β)] (t : TreeMap α β cmp) (n : Nat) : α ×
def entryAtIdxD (t : TreeMap α β cmp) (n : Nat) (fallback : α × β) : α × β :=
DTreeMap.Const.entryAtIdxD t.inner n fallback
@[inline, inherit_doc DTreeMap.keyAtIndex?]
@[inline, inherit_doc DTreeMap.keyAtIdx?]
def keyAtIdx? (t : TreeMap α β cmp) (n : Nat) : Option α :=
DTreeMap.keyAtIdx? t.inner n
@[inline, inherit_doc DTreeMap.keyAtIdx?, deprecated keyAtIdx? (since := "2025-03-25")]
def keyAtIndex? (t : TreeMap α β cmp) (n : Nat) : Option α :=
DTreeMap.keyAtIndex? t.inner n
keyAtIdx? t n
@[inline, inherit_doc DTreeMap.keyAtIndex]
@[inline, inherit_doc DTreeMap.keyAtIdx]
def keyAtIdx (t : TreeMap α β cmp) (n : Nat) (h : n < t.size) : α :=
DTreeMap.keyAtIdx t.inner n h
@[inline, inherit_doc DTreeMap.keyAtIdx, deprecated keyAtIdx (since := "2025-03-25")]
def keyAtIndex (t : TreeMap α β cmp) (n : Nat) (h : n < t.size) : α :=
DTreeMap.keyAtIndex t.inner n h
keyAtIdx t n h
@[inline, inherit_doc DTreeMap.keyAtIndex!]
@[inline, inherit_doc DTreeMap.keyAtIdx!]
def keyAtIdx! [Inhabited α] (t : TreeMap α β cmp) (n : Nat) : α :=
DTreeMap.keyAtIdx! t.inner n
@[inline, inherit_doc DTreeMap.keyAtIdx!, deprecated keyAtIdx! (since := "2025-03-25")]
def keyAtIndex! [Inhabited α] (t : TreeMap α β cmp) (n : Nat) : α :=
DTreeMap.keyAtIndex! t.inner n
keyAtIdx! t n
@[inline, inherit_doc DTreeMap.keyAtIndexD]
@[inline, inherit_doc DTreeMap.keyAtIdxD]
def keyAtIdxD (t : TreeMap α β cmp) (n : Nat) (fallback : α) : α :=
DTreeMap.keyAtIdxD t.inner n fallback
@[inline, inherit_doc DTreeMap.keyAtIdxD, deprecated keyAtIdxD (since := "2025-03-25")]
def keyAtIndexD (t : TreeMap α β cmp) (n : Nat) (fallback : α) : α :=
DTreeMap.keyAtIndexD t.inner n fallback
keyAtIdxD t n fallback
@[inline, inherit_doc DTreeMap.Const.getEntryGE?]
def getEntryGE? (t : TreeMap α β cmp) (k : α) : Option (α × β) :=
@ -551,7 +567,7 @@ def eraseMany {ρ} [ForIn Id ρ α] (t : TreeMap α β cmp) (l : ρ) : TreeMap
⟨t.inner.eraseMany l⟩
instance [Repr α] [Repr β] : Repr (TreeMap α β cmp) where
reprPrec m prec := Repr.addAppParen ("TreeMap.ofList " ++ repr m.toList) prec
reprPrec m prec := Repr.addAppParen ("Std.TreeMap.ofList " ++ repr m.toList) prec
end TreeMap

View file

@ -300,21 +300,33 @@ def entryAtIdx! [Inhabited (α × β)] (t : Raw α β cmp) (n : Nat) : α × β
def entryAtIdxD (t : Raw α β cmp) (n : Nat) (fallback : α × β) : α × β :=
DTreeMap.Raw.Const.entryAtIdxD t.inner n fallback
@[inline, inherit_doc DTreeMap.Raw.keyAtIndex?]
@[inline, inherit_doc DTreeMap.Raw.keyAtIdx?]
def keyAtIdx? (t : Raw α β cmp) (n : Nat) : Option α :=
DTreeMap.Raw.keyAtIdx? t.inner n
@[inline, inherit_doc DTreeMap.Raw.keyAtIdx?, deprecated keyAtIdx? (since := "2025-03-26")]
def keyAtIndex? (t : Raw α β cmp) (n : Nat) : Option α :=
DTreeMap.Raw.keyAtIndex? t.inner n
keyAtIdx? t n
/-!
We do not provide `keyAtIndex` for the raw trees.
We do not provide `keyAtIdx` for the raw trees.
-/
@[inline, inherit_doc DTreeMap.Raw.keyAtIndex!]
def keyAtIndex! [Inhabited α] (t : Raw α β cmp) (n : Nat) : α :=
DTreeMap.Raw.keyAtIndex! t.inner n
@[inline, inherit_doc DTreeMap.Raw.keyAtIdx!]
def keyAtIdx! [Inhabited α] (t : Raw α β cmp) (n : Nat) : α :=
DTreeMap.Raw.keyAtIdx! t.inner n
@[inline, inherit_doc DTreeMap.Raw.keyAtIndexD]
@[inline, inherit_doc DTreeMap.Raw.keyAtIdx!, deprecated keyAtIdx! (since := "2025-03-26")]
def keyAtIndex! [Inhabited α] (t : Raw α β cmp) (n : Nat) : α :=
keyAtIdx! t n
@[inline, inherit_doc DTreeMap.Raw.keyAtIdxD]
def keyAtIdxD (t : Raw α β cmp) (n : Nat) (fallback : α) : α :=
DTreeMap.Raw.keyAtIdxD t.inner n fallback
@[inline, inherit_doc DTreeMap.Raw.keyAtIdxD, deprecated keyAtIdxD (since := "2025-03-26")]
def keyAtIndexD (t : Raw α β cmp) (n : Nat) (fallback : α) : α :=
DTreeMap.Raw.keyAtIndexD t.inner n fallback
keyAtIdxD t n fallback
@[inline, inherit_doc DTreeMap.Raw.Const.getEntryGE?]
def getEntryGE? (t : Raw α β cmp) (k : α) : Option (α × β) :=
@ -549,7 +561,7 @@ def eraseMany {ρ} [ForIn Id ρ α] (t : Raw α β cmp) (l : ρ) : Raw α β cmp
⟨t.inner.eraseMany l⟩
instance [Repr α] [Repr β] : Repr (Raw α β cmp) where
reprPrec m prec := Repr.addAppParen ("TreeMap.Raw.ofList " ++ repr m.toList) prec
reprPrec m prec := Repr.addAppParen ("Std.TreeMap.Raw.ofList " ++ repr m.toList) prec
end Raw

View file

@ -238,22 +238,22 @@ def maxD (t : TreeSet α cmp) (fallback : α) : α :=
/-- Returns the `n`-th smallest element, or `none` if `n` is at least `t.size`. -/
@[inline]
def atIdx? (t : TreeSet α cmp) (n : Nat) : Option α :=
TreeMap.keyAtIndex? t.inner n
TreeMap.keyAtIdx? t.inner n
/-- Returns the `n`-th smallest element. -/
@[inline]
def atIdx (t : TreeSet α cmp) (n : Nat) (h : n < t.size) : α :=
TreeMap.keyAtIndex t.inner n h
TreeMap.keyAtIdx t.inner n h
/-- Returns the `n`-th smallest element, or panics if `n` is at least `t.size`. -/
@[inline]
def atIdx! [Inhabited α] (t : TreeSet α cmp) (n : Nat) : α :=
TreeMap.keyAtIndex! t.inner n
TreeMap.keyAtIdx! t.inner n
/-- Returns the `n`-th smallest element, or `fallback` if `n` is at least `t.size`. -/
@[inline]
def atIdxD (t : TreeSet α cmp) (n : Nat) (fallback : α) : α :=
TreeMap.keyAtIndexD t.inner n fallback
TreeMap.keyAtIdxD t.inner n fallback
/--
Tries to retrieve the smallest element that is greater than or equal to the
@ -495,7 +495,7 @@ def eraseMany {ρ} [ForIn Id ρ α] (t : TreeSet α cmp) (l : ρ) : TreeSet α c
⟨t.inner.eraseMany l⟩
instance [Repr α] : Repr (TreeSet α cmp) where
reprPrec m prec := Repr.addAppParen ("TreeSet.ofList " ++ repr m.toList) prec
reprPrec m prec := Repr.addAppParen ("Std.TreeSet.ofList " ++ repr m.toList) prec
end TreeSet

View file

@ -183,7 +183,7 @@ def maxD (t : Raw α cmp) (fallback : α) : α :=
@[inline, inherit_doc TreeSet.atIdx?]
def atIdx? (t : Raw α cmp) (n : Nat) : Option α :=
TreeMap.Raw.keyAtIndex? t.inner n
TreeMap.Raw.keyAtIdx? t.inner n
/-!
We do not provide `entryAtIdx` for the raw trees.
@ -191,11 +191,11 @@ We do not provide `entryAtIdx` for the raw trees.
@[inline, inherit_doc TreeSet.atIdx!]
def atIdx! [Inhabited α] (t : Raw α cmp) (n : Nat) : α :=
TreeMap.Raw.keyAtIndex! t.inner n
TreeMap.Raw.keyAtIdx! t.inner n
@[inline, inherit_doc TreeSet.atIdxD]
def atIdxD (t : Raw α cmp) (n : Nat) (fallback : α) : α :=
TreeMap.Raw.keyAtIndexD t.inner n fallback
TreeMap.Raw.keyAtIdxD t.inner n fallback
@[inline, inherit_doc TreeSet.getGE?]
def getGE? (t : Raw α cmp) (k : α) : Option α :=
@ -346,7 +346,7 @@ def eraseMany {ρ} [ForIn Id ρ α] (t : Raw α cmp) (l : ρ) : Raw α cmp :=
⟨t.inner.eraseMany l⟩
instance [Repr α] : Repr (Raw α cmp) where
reprPrec m prec := Repr.addAppParen ("TreeSet.Raw.ofList " ++ repr m.toList) prec
reprPrec m prec := Repr.addAppParen ("Std.TreeSet.Raw.ofList " ++ repr m.toList) prec
end Raw

File diff suppressed because it is too large Load diff