tests: rewrite test with complex types
This commit is contained in:
@@ -9,26 +9,22 @@ type Longitude = float where (-180 <= _ <= 180)
|
||||
type Difference[T] = T
|
||||
|
||||
// Complex custom type, containing two values accessible through properties
|
||||
type GeoLocation = {
|
||||
type GeoLocation = object
|
||||
|
||||
extend GeoLocation {
|
||||
prop lat: Latitude
|
||||
prop lon: Longitude
|
||||
}
|
||||
|
||||
// Define operations on our custom type
|
||||
extend GeoLocation {
|
||||
// This type is compatible with the `-` operation with another GeoLocation
|
||||
// i.e. you can subtract a GeoLocation from another GeoLocation, resulting
|
||||
// in a Difference of GeoLocations
|
||||
def __sub__: fn(GeoLocation, /) -> Difference[GeoLocation]
|
||||
}
|
||||
type GeoLocationDifference = object
|
||||
|
||||
// For complex generics, you need to specify how the genericity the properties
|
||||
// are handled
|
||||
type Difference[GeoLocation] = {
|
||||
extend GeoLocationDifference {
|
||||
prop lat: Difference[Latitude]
|
||||
prop lon: Difference[Longitude]
|
||||
}
|
||||
|
||||
// Define operations on our custom type
|
||||
|
||||
// Simple operation defined on our custom types
|
||||
extend Latitude {
|
||||
def __sub__: fn(Latitude, /) -> Difference[Latitude]
|
||||
@@ -38,13 +34,23 @@ extend Longitude {
|
||||
def __sub__: fn(Longitude, /) -> Difference[Longitude]
|
||||
}
|
||||
|
||||
extend GeoLocation {
|
||||
// This type is compatible with the `-` operation with another GeoLocation
|
||||
// i.e. you can subtract a GeoLocation from another GeoLocation, resulting
|
||||
// in a GeoLocationDifference
|
||||
def __sub__: fn(GeoLocation, /) -> GeoLocationDifference
|
||||
}
|
||||
|
||||
|
||||
// Predefined custom predicates that can be referenced in other definitions
|
||||
predicate Positive(v: float) = v >= 0
|
||||
predicate StrictlyPositive(v: float) = v > 0
|
||||
predicate Equatorial(loc: GeoLocation) = (-10 <= loc.lat <= 10)
|
||||
predicate Arctic(loc: GeoLocation) = (loc.lat >= 66)
|
||||
|
||||
type Person = {
|
||||
type Person = object
|
||||
|
||||
extend Person {
|
||||
prop name: str
|
||||
|
||||
// Property with an inline constraint
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user