TestCostModelValueProjections charges an element projection through a real evaluation. The two lists have the same length and the same number of literals, so every other term in the total is equal and the difference is the projection reading the elements themselves.
(t *testing.T)
| 5791 | // lists have the same length and the same number of literals, so every other term in the total is |
| 5792 | // equal and the difference is the projection reading the elements themselves. |
| 5793 | func TestCostModelValueProjections(t *testing.T) { |
| 5794 | env, err := NewEnv(CostModel( |
| 5795 | cost.Overload(overloads.InList, cost.EvalCost(cost.ElemTotal(cost.Arg(1)))), |
| 5796 | )) |
| 5797 | if err != nil { |
| 5798 | t.Fatalf("NewEnv() failed: %v", err) |
| 5799 | } |
| 5800 | costOf := func(expr string) uint64 { |
| 5801 | t.Helper() |
| 5802 | ast, iss := env.Compile(expr) |
| 5803 | if iss.Err() != nil { |
| 5804 | t.Fatalf("env.Compile(%q) failed: %v", expr, iss.Err()) |
| 5805 | } |
| 5806 | prg, err := env.Program(ast, CostTracking(nil)) |
| 5807 | if err != nil { |
| 5808 | t.Fatalf("env.Program() failed: %v", err) |
| 5809 | } |
| 5810 | _, det, err := prg.Eval(NoVars()) |
| 5811 | if err != nil { |
| 5812 | t.Fatalf("prg.Eval() failed: %v", err) |
| 5813 | } |
| 5814 | return *det.ActualCost() |
| 5815 | } |
| 5816 | // Total element sizes of 7 and 3 respectively. |
| 5817 | large := costOf(`'zz' in ['a', 'bbbb', 'cc']`) |
| 5818 | small := costOf(`'zz' in ['a', 'b', 'c']`) |
| 5819 | if large-small != 4 { |
| 5820 | t.Errorf("element projection charged %d - %d = %d, wanted a difference of 4", |
| 5821 | large, small, large-small) |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | func TestCostModelVersion(t *testing.T) { |
| 5826 | // A model with BeforeVersion(1, ...) covers the env compiling user-supplied models at the |
nothing calls this directly
no test coverage detected