Skip to content

Commit

Permalink
Additional coverage for static and runtime cost computations (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Mar 27, 2023
1 parent 774b625 commit a7e3b68
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions checker/cost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,33 @@ func TestCost(t *testing.T) {
expr: `true || false`,
wanted: zeroCost,
},
{
name: "or accumulated branch cost",
expr: `a || b || c || d`,
decls: []*exprpb.Decl{
decls.NewVar("a", decls.Bool),
decls.NewVar("b", decls.Bool),
decls.NewVar("c", decls.Bool),
decls.NewVar("d", decls.Bool),
},
wanted: CostEstimate{Min: 1, Max: 4},
},
{
name: "and",
expr: `true && false`,
wanted: zeroCost,
},
{
name: "and accumulated branch cost",
expr: `a && b && c && d`,
decls: []*exprpb.Decl{
decls.NewVar("a", decls.Bool),
decls.NewVar("b", decls.Bool),
decls.NewVar("c", decls.Bool),
decls.NewVar("d", decls.Bool),
},
wanted: CostEstimate{Min: 1, Max: 4},
},
{
name: "lt",
expr: `1 < 2`,
Expand Down
35 changes: 35 additions & 0 deletions interpreter/runtimecost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,24 @@ func TestRuntimeCost(t *testing.T) {
expr: `true || false`,
want: 0,
},

{
name: "or accumulated branch cost",
expr: `a || b || c || d`,
decls: []*exprpb.Decl{
decls.NewVar("a", decls.Bool),
decls.NewVar("b", decls.Bool),
decls.NewVar("c", decls.Bool),
decls.NewVar("d", decls.Bool),
},
in: map[string]any{
"a": false,
"b": false,
"c": false,
"d": false,
},
want: 4,
},
{
name: "and",
expr: `true && false`,
Expand All @@ -408,6 +426,23 @@ func TestRuntimeCost(t *testing.T) {
expr: `false && true`,
want: 0,
},
{
name: "and accumulated branch cost",
expr: `a && b && c && d`,
decls: []*exprpb.Decl{
decls.NewVar("a", decls.Bool),
decls.NewVar("b", decls.Bool),
decls.NewVar("c", decls.Bool),
decls.NewVar("d", decls.Bool),
},
in: map[string]any{
"a": true,
"b": true,
"c": true,
"d": true,
},
want: 4,
},
{
name: "lt",
expr: `1 < 2`,
Expand Down

0 comments on commit a7e3b68

Please sign in to comment.