mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #806 from svanharmelen/b-helper-schema-sets-init
core: sets should init only once...
This commit is contained in:
commit
5c0fc0cfe0
@ -59,7 +59,7 @@ func (s *Set) List() []interface{} {
|
|||||||
// a new third set that has only the elements unique to this set.
|
// a new third set that has only the elements unique to this set.
|
||||||
func (s *Set) Difference(other *Set) *Set {
|
func (s *Set) Difference(other *Set) *Set {
|
||||||
result := &Set{F: s.F}
|
result := &Set{F: s.F}
|
||||||
result.init()
|
result.once.Do(result.init)
|
||||||
|
|
||||||
for k, v := range s.m {
|
for k, v := range s.m {
|
||||||
if _, ok := other.m[k]; !ok {
|
if _, ok := other.m[k]; !ok {
|
||||||
@ -74,7 +74,7 @@ func (s *Set) Difference(other *Set) *Set {
|
|||||||
// and returns a new third set.
|
// and returns a new third set.
|
||||||
func (s *Set) Intersection(other *Set) *Set {
|
func (s *Set) Intersection(other *Set) *Set {
|
||||||
result := &Set{F: s.F}
|
result := &Set{F: s.F}
|
||||||
result.init()
|
result.once.Do(result.init)
|
||||||
|
|
||||||
for k, v := range s.m {
|
for k, v := range s.m {
|
||||||
if _, ok := other.m[k]; ok {
|
if _, ok := other.m[k]; ok {
|
||||||
@ -89,7 +89,7 @@ func (s *Set) Intersection(other *Set) *Set {
|
|||||||
// set.
|
// set.
|
||||||
func (s *Set) Union(other *Set) *Set {
|
func (s *Set) Union(other *Set) *Set {
|
||||||
result := &Set{F: s.F}
|
result := &Set{F: s.F}
|
||||||
result.init()
|
result.once.Do(result.init)
|
||||||
|
|
||||||
for k, v := range s.m {
|
for k, v := range s.m {
|
||||||
result.m[k] = v
|
result.m[k] = v
|
||||||
|
@ -40,8 +40,11 @@ func TestSetDifference(t *testing.T) {
|
|||||||
s2.Add(5)
|
s2.Add(5)
|
||||||
s2.Add(25)
|
s2.Add(25)
|
||||||
|
|
||||||
expected := []interface{}{1}
|
difference := s1.Difference(s2)
|
||||||
actual := s1.Difference(s2).List()
|
difference.Add(2)
|
||||||
|
|
||||||
|
expected := []interface{}{1, 2}
|
||||||
|
actual := difference.List()
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("bad: %#v", actual)
|
t.Fatalf("bad: %#v", actual)
|
||||||
}
|
}
|
||||||
@ -57,8 +60,11 @@ func TestSetIntersection(t *testing.T) {
|
|||||||
s2.Add(5)
|
s2.Add(5)
|
||||||
s2.Add(25)
|
s2.Add(25)
|
||||||
|
|
||||||
expected := []interface{}{5}
|
intersection := s1.Intersection(s2)
|
||||||
actual := s1.Intersection(s2).List()
|
intersection.Add(2)
|
||||||
|
|
||||||
|
expected := []interface{}{2, 5}
|
||||||
|
actual := intersection.List()
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("bad: %#v", actual)
|
t.Fatalf("bad: %#v", actual)
|
||||||
}
|
}
|
||||||
@ -74,8 +80,11 @@ func TestSetUnion(t *testing.T) {
|
|||||||
s2.Add(5)
|
s2.Add(5)
|
||||||
s2.Add(25)
|
s2.Add(25)
|
||||||
|
|
||||||
expected := []interface{}{1, 5, 25}
|
union := s1.Union(s2)
|
||||||
actual := s1.Union(s2).List()
|
union.Add(2)
|
||||||
|
|
||||||
|
expected := []interface{}{1, 2, 5, 25}
|
||||||
|
actual := union.List()
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("bad: %#v", actual)
|
t.Fatalf("bad: %#v", actual)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user