this repo has no description
1// Copyright 2025 CUE Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package adt
16
17import (
18 "slices"
19 "testing"
20)
21
22func TestMergeCloseInfo(t *testing.T) {
23 tests := []struct {
24 name string
25 nv *nodeContext
26 nw *nodeContext
27 expected *nodeContext
28 }{{
29 name: "merge with no conflicts",
30 nv: &nodeContext{
31 node: &Vertex{
32 Arcs: []*Vertex{
33 {Label: 1, state: &nodeContext{}},
34 },
35 },
36 conjunctInfo: []conjunctInfo{
37 {id: 1},
38 },
39 replaceIDs: []replaceID{
40 {from: 1, to: 2},
41 },
42 },
43 nw: &nodeContext{
44 node: &Vertex{
45 Arcs: []*Vertex{
46 {Label: 1, state: &nodeContext{}},
47 },
48 },
49 conjunctInfo: []conjunctInfo{
50 {id: 2},
51 },
52 replaceIDs: []replaceID{
53 {from: 2, to: 3},
54 },
55 },
56 expected: &nodeContext{
57 conjunctInfo: []conjunctInfo{
58 {id: 1},
59 {id: 2},
60 },
61 replaceIDs: []replaceID{
62 {from: 1, to: 2},
63 {from: 2, to: 3},
64 },
65 },
66 }, {
67 name: "merge with conflicts",
68 nv: &nodeContext{
69 node: &Vertex{
70 Arcs: []*Vertex{
71 {Label: 1, state: &nodeContext{}},
72 },
73 },
74 conjunctInfo: []conjunctInfo{
75 {id: 1},
76 },
77 replaceIDs: []replaceID{
78 {from: 1, to: 2},
79 },
80 },
81 nw: &nodeContext{
82 node: &Vertex{
83 Arcs: []*Vertex{
84 {Label: 2, state: &nodeContext{}},
85 },
86 },
87 conjunctInfo: []conjunctInfo{
88 {id: 1},
89 },
90 replaceIDs: []replaceID{
91 {from: 1, to: 3},
92 },
93 },
94 expected: &nodeContext{
95 conjunctInfo: []conjunctInfo{
96 {id: 1},
97 },
98 replaceIDs: []replaceID{
99 {from: 1, to: 2},
100 {from: 1, to: 3},
101 },
102 },
103 },
104 }
105
106 for _, tt := range tests {
107 t.Run(tt.name, func(t *testing.T) {
108 mergeCloseInfo(tt.nv, tt.nw)
109 if !slices.Equal(tt.nv.conjunctInfo, tt.expected.conjunctInfo) {
110 t.Errorf("conjunctInfo got %v, want %v", tt.nv.conjunctInfo, tt.expected.conjunctInfo)
111 }
112 if !slices.Equal(tt.nv.replaceIDs, tt.expected.replaceIDs) {
113 t.Errorf("replaceIDs got %v, want %v", tt.nv.replaceIDs, tt.expected.replaceIDs)
114 }
115 })
116 }
117}