-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compare a base csv with the new csv and print changes
- Loading branch information
1 parent
9e0c77f
commit 701f85e
Showing
5 changed files
with
111 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package digest | ||
|
||
func Compare(baseDigest, newDigest map[uint64]uint64) (additions []uint64, modifications []uint64) { | ||
maxSize := len(newDigest) | ||
additions = make([]uint64, maxSize) | ||
modifications = make([]uint64, maxSize) | ||
|
||
additionCounter := 0 | ||
modificationCounter := 0 | ||
for k, newVal := range newDigest { | ||
if oldVal, present := baseDigest[k]; present { | ||
if newVal != oldVal { | ||
//Modifications | ||
modifications[modificationCounter] = k | ||
modificationCounter++ | ||
} | ||
} else { | ||
//Additions | ||
additions[additionCounter] = k | ||
additionCounter++ | ||
} | ||
} | ||
return additions[:additionCounter], modifications[:modificationCounter] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package digest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCompare(t *testing.T) { | ||
baseDigest := map[uint64]uint64{ | ||
10000106069522789940: 11608188164212916000, | ||
10000305084889337335: 11796412213504516000, | ||
10024909476616779194: 14500526491611670000, | ||
1004896778135186857: 15778011848259830000, | ||
} | ||
|
||
newDigest := map[uint64]uint64{ | ||
10000106069522789940: 11608188164212916000, | ||
10000305084889337335: 11796412213504516001, | ||
10049141081086325814: 12259600610026582000, | ||
} | ||
|
||
additions, modifications := Compare(baseDigest, newDigest) | ||
|
||
expectedAdditions := []uint64{10049141081086325814} | ||
expectedModifications := []uint64{10000305084889337335} | ||
|
||
assert.Equal(t, expectedAdditions, additions) | ||
assert.Equal(t, expectedModifications, modifications) | ||
} |