1
0
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:
Delyan Angelov 2022-10-16 12:57:34 +03:00
parent 710c2b22da
commit c02974622f
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -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)
}