MCPcopy Index your code
hub / github.com/google/mangle / TestResolveHeadTime_VariableBound

Function TestResolveHeadTime_VariableBound

engine/temporal_test.go:702–751  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

700}
701
702func TestResolveHeadTime_VariableBound(t *testing.T) {
703 evalTime := ast.Date(2024, 1, 15)
704
705 // Create a substitution with a bound variable
706 subst := unionfind.New()
707 startTime := ast.Date(2024, 2, 1)
708 endTime := ast.Date(2024, 2, 28)
709
710 // Bind T1 and T2 to timestamp values (as nanoseconds)
711 t1Var := ast.Variable{Symbol: "T1"}
712 t2Var := ast.Variable{Symbol: "T2"}
713 subst, _ = unionfind.UnifyTermsExtend(
714 []ast.BaseTerm{t1Var},
715 []ast.BaseTerm{ast.Number(startTime.UnixNano())},
716 subst,
717 )
718 subst, _ = unionfind.UnifyTermsExtend(
719 []ast.BaseTerm{t2Var},
720 []ast.BaseTerm{ast.Number(endTime.UnixNano())},
721 subst,
722 )
723
724 // Create an interval with variable bounds
725 headTime := ast.NewInterval(
726 ast.NewVariableBound(t1Var),
727 ast.NewVariableBound(t2Var),
728 )
729
730 result, err := ResolveHeadTime(&headTime, subst, evalTime)
731 if err != nil {
732 t.Fatalf("ResolveHeadTime returned error: %v", err)
733 }
734 if result == nil {
735 t.Fatal("ResolveHeadTime returned nil")
736 }
737
738 // Check that the variables were resolved
739 if result.Start.Type != ast.TimestampBound {
740 t.Errorf("ResolveHeadTime start type = %v, want TimestampBound", result.Start.Type)
741 }
742 if result.Start.Timestamp != startTime.UnixNano() {
743 t.Errorf("ResolveHeadTime start = %v, want %v", result.Start.Timestamp, startTime.UnixNano())
744 }
745 if result.End.Type != ast.TimestampBound {
746 t.Errorf("ResolveHeadTime end type = %v, want TimestampBound", result.End.Type)
747 }
748 if result.End.Timestamp != endTime.UnixNano() {
749 t.Errorf("ResolveHeadTime end = %v, want %v", result.End.Timestamp, endTime.UnixNano())
750 }
751}
752
753func TestEvalClauseWithTemporalHead(t *testing.T) {
754 evalTime := ast.Date(2024, 1, 15)

Callers

nothing calls this directly

Calls 7

DateFunction · 0.92
NewFunction · 0.92
UnifyTermsExtendFunction · 0.92
NumberFunction · 0.92
NewIntervalFunction · 0.92
NewVariableBoundFunction · 0.92
ResolveHeadTimeFunction · 0.85

Tested by

no test coverage detected