github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/m3ninx/search/query/disjunction_test.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package query 22 23 import ( 24 "testing" 25 26 "github.com/m3db/m3/src/m3ninx/search" 27 28 "github.com/stretchr/testify/require" 29 ) 30 31 func TestDisjunctionQuery(t *testing.T) { 32 tests := []struct { 33 name string 34 queries []search.Query 35 }{ 36 { 37 name: "no queries provided", 38 }, 39 { 40 name: "a single query provided", 41 queries: []search.Query{ 42 NewTermQuery([]byte("fruit"), []byte("apple")), 43 }, 44 }, 45 { 46 name: "multiple queries provided", 47 queries: []search.Query{ 48 NewTermQuery([]byte("fruit"), []byte("apple")), 49 NewTermQuery([]byte("vegetable"), []byte("carrot")), 50 }, 51 }, 52 } 53 54 for _, test := range tests { 55 t.Run(test.name, func(t *testing.T) { 56 q := NewDisjunctionQuery(test.queries) 57 _, err := q.Searcher() 58 require.NoError(t, err) 59 }) 60 } 61 } 62 63 func TestDisjunctionQueryEqual(t *testing.T) { 64 tests := []struct { 65 name string 66 left, right search.Query 67 expected bool 68 }{ 69 { 70 name: "empty queries", 71 left: NewDisjunctionQuery(nil), 72 right: NewDisjunctionQuery(nil), 73 expected: true, 74 }, 75 { 76 name: "equal queries", 77 left: NewDisjunctionQuery([]search.Query{ 78 NewTermQuery([]byte("fruit"), []byte("apple")), 79 NewTermQuery([]byte("fruit"), []byte("banana")), 80 }), 81 right: NewDisjunctionQuery([]search.Query{ 82 NewTermQuery([]byte("fruit"), []byte("apple")), 83 NewTermQuery([]byte("fruit"), []byte("banana")), 84 }), 85 expected: true, 86 }, 87 { 88 name: "single query", 89 left: NewDisjunctionQuery([]search.Query{ 90 NewTermQuery([]byte("fruit"), []byte("apple")), 91 }), 92 right: NewTermQuery([]byte("fruit"), []byte("apple")), 93 expected: true, 94 }, 95 { 96 name: "different order", 97 left: NewDisjunctionQuery([]search.Query{ 98 NewTermQuery([]byte("fruit"), []byte("apple")), 99 NewTermQuery([]byte("fruit"), []byte("banana")), 100 }), 101 right: NewDisjunctionQuery([]search.Query{ 102 NewTermQuery([]byte("fruit"), []byte("banana")), 103 NewTermQuery([]byte("fruit"), []byte("apple")), 104 }), 105 expected: true, 106 }, 107 } 108 109 for _, test := range tests { 110 t.Run(test.name, func(t *testing.T) { 111 require.Equal(t, test.expected, test.left.Equal(test.right)) 112 }) 113 } 114 }