Reviewed-on: #17 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package parser
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
|
)
|
|
|
|
const Test_File_Path = "../../tests/numbers.txt"
|
|
|
|
// Remove duplicates
|
|
func Test_RemoveDups(t *testing.T) {
|
|
parser := NumberParser{FilePath: Test_File_Path}
|
|
finalAmount := parser.FileDump()
|
|
|
|
if len(finalAmount) < 1 {
|
|
t.Error("Dump should not be empty")
|
|
}
|
|
|
|
testValues := []contact.Contact{
|
|
{PhoneNumber: "+12175550194"},
|
|
{PhoneNumber: "+16025550177"},
|
|
{PhoneNumber: "+17135550167"},
|
|
{PhoneNumber: "+16085550190"},
|
|
{PhoneNumber: "+13055550112"},
|
|
{PhoneNumber: "+14155550135"},
|
|
{PhoneNumber: "+13175550123"},
|
|
{PhoneNumber: "+13605550158"},
|
|
}
|
|
|
|
aSize := len(finalAmount)
|
|
bSize := len(testValues)
|
|
if aSize != bSize {
|
|
t.Error("Data has varrying sizes A", aSize, " B", bSize)
|
|
}
|
|
if !dataEqual(finalAmount, testValues) {
|
|
fmt.Println("Printing final amount")
|
|
for _, val := range finalAmount {
|
|
fmt.Println("PhoneNumber:", val.PhoneNumber)
|
|
}
|
|
fmt.Println("Printing test values")
|
|
for _, val := range testValues {
|
|
fmt.Println("PhoneNumber:", val.PhoneNumber)
|
|
}
|
|
|
|
t.Error("Data has not be updated")
|
|
}
|
|
}
|
|
|
|
func dataEqual(a, b []contact.Contact) bool {
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
|
|
for i := range a {
|
|
foundIt := false
|
|
for j := range b {
|
|
if a[i] == b[j] {
|
|
foundIt = true
|
|
}
|
|
}
|
|
|
|
if !foundIt {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|