-
Notifications
You must be signed in to change notification settings - Fork 24
/
diff.go
154 lines (139 loc) · 4.06 KB
/
diff.go
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package params
import "fmt"
// DiffsAll reports all the cases where the same param path is being set
// to different values across different sets
func (ps *Sets) DiffsAll() string {
pd := ""
sz := len(*ps)
for i, set := range *ps {
for j := i + 1; j < sz; j++ {
oset := (*ps)[j]
spd := set.Diffs(oset)
if spd != "" {
pd += "//////////////////////////////////////\n"
pd += spd
}
}
}
return pd
}
// DiffsFirst reports all the cases where the same param path is being set
// to different values between the first set (e.g., the "Base" set) and
// all other sets
func (ps *Sets) DiffsFirst() string {
pd := ""
sz := len(*ps)
if sz < 2 {
return ""
}
set := (*ps)[0]
for j := 1; j < sz; j++ {
oset := (*ps)[j]
spd := set.Diffs(oset)
if spd != "" {
pd += "//////////////////////////////////////\n"
pd += spd
}
}
return pd
}
// DiffsWithin reports all the cases where the same param path is being set
// to different values within different sheets in given set
func (ps *Sets) DiffsWithin(setName string) string {
set, err := ps.SetByNameTry(setName)
if err != nil {
return err.Error()
}
return set.DiffsWithin()
}
/////////////////////////////////////////////////////////
// Set
// Diffs reports all the cases where the same param path is being set
// to different values between this set and the other set.
func (ps *Set) Diffs(ops *Set) string {
pd := ""
for snm, sht := range ps.Sheets {
for osnm, osht := range ops.Sheets {
spd := sht.Diffs(osht, ps.Name+"."+snm, ops.Name+"."+osnm)
pd += spd
}
}
return pd
}
// DiffsWithin reports all the cases where the same param path is being set
// to different values within different sheets
func (ps *Set) DiffsWithin() string {
return ps.Sheets.DiffsWithin()
}
/////////////////////////////////////////////////////////
// Sheets
// DiffsWithin reports all the cases where the same param path is being set
// to different values within different sheets
func (ps *Sheets) DiffsWithin() string {
pd := "Within Sheet Diffs (Same param path set differentially within a Sheet):\n\n"
for snm, sht := range *ps {
spd := sht.DiffsWithin(snm)
pd += spd
}
got := false
for snm, sht := range *ps {
for osnm, osht := range *ps {
spd := sht.Diffs(osht, snm, osnm)
if !got {
pd += "////////////////////////////////////////////////////////////////////////////////////\n"
pd += "Between Sheet Diffs (Same param path set differentially between two Sheets):\n\n"
got = true
}
pd += spd
}
}
return pd
}
/////////////////////////////////////////////////////////
// Sheet
// Diffs reports all the cases where the same param path is being set
// to different values between this sheeet and the other sheeet.
func (ps *Sheet) Diffs(ops *Sheet, setNm1, setNm2 string) string {
pd := ""
for _, sel := range *ps {
for _, osel := range *ops {
spd := sel.Params.Diffs(&sel.Params, setNm1+":"+sel.Sel, setNm2+":"+osel.Sel)
pd += spd
}
}
return pd
}
// DiffsWithin reports all the cases where the same param path is being set
// to different values within different Sel's in this Sheet.
func (ps *Sheet) DiffsWithin(shtNm string) string {
pd := ""
sz := len(*ps)
for i, sel := range *ps {
for j := i + 1; j < sz; j++ {
osel := (*ps)[j]
spd := sel.Params.Diffs(&sel.Params, shtNm+":"+sel.Sel, shtNm+":"+osel.Sel)
pd += spd
}
}
return pd
}
/////////////////////////////////////////////////////////
// Params
// Diffs returns comparison between all params in this params
// versus the other params, where the path is the same but the
// parameter value is different. Nm1 is the name / id of the
// 'this' Params, and nm2 is for the other params.
func (pr *Params) Diffs(op *Params, nm1, nm2 string) string {
pd := ""
for pt, pv := range *pr {
for opt, opv := range *op {
if pt == opt && pv != opv {
pd += fmt.Sprintf("%s:\t\t %s = %v \t|\t %s = %v,\n", pt, nm1, pv, nm2, opv)
}
}
}
return pd
}