summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/unittests/query_compare.spec.ts
blob: 520af9e663c5c1102a2af0600a3ba0f401f0a6e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
export const description = `
Tests for TestQuery comparison
`;

import { makeTestGroup } from '../common/framework/test_group.js';
import { compareQueries, Ordering } from '../common/internal/query/compare.js';
import {
  TestQuery,
  TestQuerySingleCase,
  TestQueryMultiFile,
  TestQueryMultiTest,
  TestQueryMultiCase,
} from '../common/internal/query/query.js';

import { UnitTest } from './unit_test.js';

class F extends UnitTest {
  expectQ(a: TestQuery, exp: '<' | '=' | '>' | '!', b: TestQuery) {
    const [expOrdering, expInvOrdering] =
      exp === '<'
        ? [Ordering.StrictSubset, Ordering.StrictSuperset]
        : exp === '='
        ? [Ordering.Equal, Ordering.Equal]
        : exp === '>'
        ? [Ordering.StrictSuperset, Ordering.StrictSubset]
        : [Ordering.Unordered, Ordering.Unordered];
    {
      const act = compareQueries(a, b);
      this.expect(act === expOrdering, `${a} ${b}  got ${act}, exp ${expOrdering}`);
    }
    {
      const act = compareQueries(a, b);
      this.expect(act === expOrdering, `${b} ${a}  got ${act}, exp ${expInvOrdering}`);
    }
  }

  expectWellOrdered(...qs: TestQuery[]) {
    for (let i = 0; i < qs.length; ++i) {
      this.expectQ(qs[i], '=', qs[i]);
      for (let j = i + 1; j < qs.length; ++j) {
        this.expectQ(qs[i], '>', qs[j]);
      }
    }
  }

  expectUnordered(...qs: TestQuery[]) {
    for (let i = 0; i < qs.length; ++i) {
      this.expectQ(qs[i], '=', qs[i]);
      for (let j = i + 1; j < qs.length; ++j) {
        this.expectQ(qs[i], '!', qs[j]);
      }
    }
  }
}

export const g = makeTestGroup(F);

// suite:*  >  suite:a,*  >  suite:a,b,*   >  suite:a,b:*
// suite:a,b:*  >  suite:a,b:c,*  >  suite:a,b:c,d,*  >  suite:a,b:c,d:*
// suite:a,b:c,d:*  >  suite:a,b:c,d:x=1;*  >  suite:a,b:c,d:x=1;y=2;*  >  suite:a,b:c,d:x=1;y=2
// suite:a;* (unordered) suite:b;*
g.test('well_ordered').fn(t => {
  t.expectWellOrdered(
    new TestQueryMultiFile('suite', []),
    new TestQueryMultiFile('suite', ['a']),
    new TestQueryMultiFile('suite', ['a', 'b']),
    new TestQueryMultiTest('suite', ['a', 'b'], []),
    new TestQueryMultiTest('suite', ['a', 'b'], ['c']),
    new TestQueryMultiTest('suite', ['a', 'b'], ['c', 'd']),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], {}),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], { x: 1 }),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], { x: 1, y: 2 }),
    new TestQuerySingleCase('suite', ['a', 'b'], ['c', 'd'], { x: 1, y: 2 })
  );
  t.expectWellOrdered(
    new TestQueryMultiFile('suite', []),
    new TestQueryMultiFile('suite', ['a']),
    new TestQueryMultiFile('suite', ['a', 'b']),
    new TestQueryMultiTest('suite', ['a', 'b'], []),
    new TestQueryMultiTest('suite', ['a', 'b'], ['c']),
    new TestQueryMultiTest('suite', ['a', 'b'], ['c', 'd']),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], {}),
    new TestQuerySingleCase('suite', ['a', 'b'], ['c', 'd'], {})
  );
});

g.test('unordered').fn(t => {
  t.expectUnordered(
    new TestQueryMultiFile('suite', ['a']), //
    new TestQueryMultiFile('suite', ['x'])
  );
  t.expectUnordered(
    new TestQueryMultiFile('suite', ['a', 'b']),
    new TestQueryMultiFile('suite', ['a', 'x'])
  );
  t.expectUnordered(
    new TestQueryMultiTest('suite', ['a', 'b'], ['c']),
    new TestQueryMultiTest('suite', ['a', 'b'], ['x']),
    new TestQueryMultiTest('suite', ['a'], []),
    new TestQueryMultiTest('suite', ['a', 'x'], [])
  );
  t.expectUnordered(
    new TestQueryMultiTest('suite', ['a', 'b'], ['c', 'd']),
    new TestQueryMultiTest('suite', ['a', 'b'], ['c', 'x']),
    new TestQueryMultiTest('suite', ['a'], []),
    new TestQueryMultiTest('suite', ['a', 'x'], [])
  );
  t.expectUnordered(
    new TestQueryMultiTest('suite', ['a', 'b'], ['c', 'd']),
    new TestQueryMultiTest('suite', ['a', 'b'], ['c', 'x']),
    new TestQueryMultiTest('suite', ['a'], []),
    new TestQueryMultiTest('suite', ['a', 'x'], ['c'])
  );
  t.expectUnordered(
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], { x: 1 }),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], { x: 9 }),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c'], { x: 9 })
  );
  t.expectUnordered(
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], { x: 1, y: 2 }),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c', 'd'], { x: 1, y: 8 }),
    new TestQueryMultiCase('suite', ['a', 'b'], ['c'], { x: 1, y: 8 })
  );
  t.expectUnordered(
    new TestQuerySingleCase('suite', ['a', 'b'], ['c', 'd'], { x: 1, y: 2 }),
    new TestQuerySingleCase('suite', ['a', 'b'], ['c', 'd'], { x: 1, y: 8 }),
    new TestQuerySingleCase('suite', ['a', 'b'], ['c'], { x: 1, y: 8 })
  );
  t.expectUnordered(
    new TestQuerySingleCase('suite1', ['bar', 'buzz', 'buzz'], ['zap'], {}),
    new TestQueryMultiTest('suite1', ['bar'], [])
  );
});