2020-12-04 05:43:28 +01:00
|
|
|
module main
|
|
|
|
|
2021-06-26 17:09:52 +02:00
|
|
|
import geometry { Line, Point, PointCond, Shape, point_str }
|
2021-05-27 09:17:08 +02:00
|
|
|
|
|
|
|
fn point_is(p Point, cond PointCond) bool {
|
|
|
|
return cond(p)
|
|
|
|
}
|
2020-12-04 05:43:28 +01:00
|
|
|
|
2020-12-07 18:13:03 +01:00
|
|
|
fn test_imported_symbols_types() {
|
2021-03-27 18:29:57 +01:00
|
|
|
// struct init
|
|
|
|
p0 := Point{
|
|
|
|
x: 10
|
|
|
|
y: 20
|
|
|
|
}
|
|
|
|
p1 := Point{
|
|
|
|
x: 40
|
|
|
|
y: 60
|
|
|
|
}
|
|
|
|
// array init
|
|
|
|
l0 := Line{
|
|
|
|
ps: [p0, p1]
|
|
|
|
}
|
|
|
|
assert l0.ps[0].y == 20
|
2021-05-27 09:17:08 +02:00
|
|
|
|
|
|
|
cond := fn (p Point) bool {
|
|
|
|
return p.x == 10
|
|
|
|
}
|
|
|
|
assert point_is(p0, cond)
|
2020-12-07 18:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_imported_symbols_functions() {
|
2021-03-27 18:29:57 +01:00
|
|
|
p0 := Point{
|
|
|
|
x: 20
|
|
|
|
y: 40
|
|
|
|
}
|
2021-03-07 16:44:38 +01:00
|
|
|
// method
|
2020-12-07 18:13:03 +01:00
|
|
|
assert p0.str() == '20 40'
|
|
|
|
// function
|
2021-03-27 18:29:57 +01:00
|
|
|
assert point_str(p0) == '20 40'
|
2020-12-07 18:13:03 +01:00
|
|
|
}
|
2020-12-04 05:43:28 +01:00
|
|
|
|
2021-02-21 11:13:52 +01:00
|
|
|
fn vertex_count(s Shape) int {
|
|
|
|
return match s {
|
|
|
|
.circle { 0 }
|
|
|
|
.triangle { 3 }
|
|
|
|
.rectangle { 4 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_imported_symbols_enums() {
|
|
|
|
assert vertex_count(.triangle) == 3
|
2021-03-07 16:44:38 +01:00
|
|
|
assert vertex_count(Shape.triangle) == 3
|
2021-02-21 11:13:52 +01:00
|
|
|
}
|