aboutsummaryrefslogtreecommitdiffstats
path: root/reader
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2019-11-11 13:46:10 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2019-11-11 13:46:10 +0000
commitbece959199edef560b7e180044dd2b04a2dba52e (patch)
treec90f212ccce566ae0d662ca699be255273aeb624 /reader
parent1e2f179ad8b3ee4facf9ade600038dd70017f590 (diff)
added test for counting sheets in datamap
Diffstat (limited to 'reader')
-rw-r--r--reader/reader.go22
-rw-r--r--reader/reader_test.go11
2 files changed, 33 insertions, 0 deletions
diff --git a/reader/reader.go b/reader/reader.go
index bd0a1f0..54ec2cc 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -39,6 +39,28 @@ func Keylens(dml DatamapLine) (int, int) {
return len(dml.Key), len(dml.Sheet)
}
+func sheetInSlice(list []string, key string) bool {
+ for _, x := range list {
+ if x == key {
+ return true
+ }
+ }
+ return false
+}
+
+// getSheets returns the number of Sheet field entries
+// in a slice of DatamapLine structs
+func getSheets(dmls []DatamapLine) int {
+ var sheetNames []string
+ for _, dml := range dmls {
+ if sheetInSlice(sheetNames, dml.Sheet) == false {
+ sheetNames = append(sheetNames, dml.Sheet)
+ }
+ }
+ fmt.Printf("sheetNames is %v", sheetNames)
+ return len(sheetNames)
+}
+
//ReadDML returns a slice of DatamapLine structs
func ReadDML(path string) ([]DatamapLine, error) {
var s []DatamapLine
diff --git a/reader/reader_test.go b/reader/reader_test.go
index ca1c7c6..37256d8 100644
--- a/reader/reader_test.go
+++ b/reader/reader_test.go
@@ -1,6 +1,7 @@
package reader
import (
+ "fmt"
"log"
"testing"
)
@@ -90,5 +91,15 @@ func TestAlphas(t *testing.T) {
if ecs[52] != "BA" {
t.Errorf("Expected BA, got %v", ecs[52])
}
+}
+func TestDMLSliceToMap(t *testing.T) {
+ slice, _ := ReadDML("testdata/datamap.csv")
+ t.Logf("Line %v", slice[0])
+ sheetNo := getSheets(slice)
+ fmt.Print(sheetNo)
+ if sheetNo != 14 {
+ t.Errorf("Expected 14 sheets in slice, got %d",
+ sheetNo)
+ }
}