MCPcopy
hub / github.com/google/mangle / TestInterval

Function TestInterval

ast/temporal_test.go:137–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestInterval(t *testing.T) {
138 t1 := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
139 t2 := time.Date(2023, 6, 15, 0, 0, 0, 0, time.UTC)
140
141 tests := []struct {
142 name string
143 interval Interval
144 wantStr string
145 isEternal bool
146 isPoint bool
147 }{
148 {
149 name: "concrete interval",
150 interval: NewInterval(NewTimestampBound(t1), NewTimestampBound(t2)),
151 wantStr: "@[2020-01-01T00:00:00Z, 2023-06-15T00:00:00Z]",
152 isEternal: false,
153 isPoint: false,
154 },
155 {
156 name: "eternal interval",
157 interval: EternalInterval(),
158 wantStr: "",
159 isEternal: true,
160 isPoint: false,
161 },
162 {
163 name: "point interval",
164 interval: NewPointInterval(t1),
165 wantStr: "@[2020-01-01T00:00:00Z]",
166 isEternal: false,
167 isPoint: true,
168 },
169 {
170 name: "half-open interval (unbounded end)",
171 interval: NewInterval(NewTimestampBound(t1), PositiveInfinity()),
172 wantStr: "@[2020-01-01T00:00:00Z, _]",
173 isEternal: false,
174 isPoint: false,
175 },
176 {
177 name: "interval with variable",
178 interval: NewInterval(NewTimestampBound(t1), NewVariableBound(Variable{"T"})),
179 wantStr: "@[2020-01-01T00:00:00Z, T]",
180 isEternal: false,
181 isPoint: false,
182 },
183 }
184
185 for _, tt := range tests {
186 t.Run(tt.name, func(t *testing.T) {
187 if got := tt.interval.String(); got != tt.wantStr {
188 t.Errorf("Interval.String() = %v, want %v", got, tt.wantStr)
189 }
190 if got := tt.interval.IsEternal(); got != tt.isEternal {
191 t.Errorf("Interval.IsEternal() = %v, want %v", got, tt.isEternal)
192 }
193 if got := tt.interval.IsPoint(); got != tt.isPoint {
194 t.Errorf("Interval.IsPoint() = %v, want %v", got, tt.isPoint)

Callers

nothing calls this directly

Calls 9

NewIntervalFunction · 0.85
NewTimestampBoundFunction · 0.85
EternalIntervalFunction · 0.85
NewPointIntervalFunction · 0.85
PositiveInfinityFunction · 0.85
NewVariableBoundFunction · 0.85
IsEternalMethod · 0.80
IsPointMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected