mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: add checks_for_operator_overrides_should_happen_on_the_concrete_types_when_using_generics_test.v
This commit is contained in:
parent
710c2b22da
commit
c02974622f
@ -0,0 +1,31 @@
|
||||
module main
|
||||
|
||||
import datatypes
|
||||
|
||||
struct Item {
|
||||
priority int
|
||||
}
|
||||
|
||||
fn (a Item) < (b Item) bool {
|
||||
return a.priority < b.priority
|
||||
}
|
||||
|
||||
fn (a Item) == (b Item) bool {
|
||||
return a.priority == b.priority
|
||||
}
|
||||
|
||||
// Issue https://github.com/vlang/v/issues/13318
|
||||
fn test_comparison_operator_override_works_with_generic_datatypes() {
|
||||
mut heap := datatypes.MinHeap<Item>{}
|
||||
heap.insert(Item{10})
|
||||
assert heap.peek()?.priority == 10
|
||||
heap.insert(Item{100})
|
||||
assert heap.peek()?.priority == 10
|
||||
heap.insert(Item{2})
|
||||
assert heap.peek()?.priority == 2
|
||||
heap.insert(Item{5})
|
||||
assert heap.peek()?.priority == 2
|
||||
heap.insert(Item{1})
|
||||
assert heap.peek()?.priority == 1
|
||||
println(heap)
|
||||
}
|
Loading…
Reference in New Issue
Block a user