Commit 782867b
Changed files (2)
serverHandlers.go
@@ -31,6 +31,8 @@ func buildRecordArray(numQuestions int, selectedCategories []string) ([]Record,
return recordArray, err
}
+// parseBluePrint takes a list of category indices and returns
+// the chosen string representation of the categories
func parseBluePrint(blueprint string) ([]string, error) {
splits := strings.Split(blueprint, "-")
chosenCategories := make([]string, len(splits))
serverHandlers_test.go
@@ -1,6 +1,31 @@
package main
-// import (
-// "log"
-// "testing"
-// )
+import (
+ "testing"
+)
+
+// TestBuildingBlueprint tests the blueprint building
+// function
+func TestBuildingBlueprint(t *testing.T) {
+ categories = nil
+ categories = []string{"thing", "thing1", "thing2", "thing3", "thing4"}
+ cats, err := parseBluePrint("2-0-3")
+ if err != nil {
+ t.Errorf("Error for building blueprint: %+v", err)
+ t.FailNow()
+ }
+ if len(cats) != 3 {
+ t.Error("cats is wrong length: %+v", cats)
+ }
+ for _, cat := range []string{"thing2", "thing", "thing3"} {
+ elementFound := false
+ for _, origCat := range cats {
+ if origCat == cat {
+ elementFound = true
+ }
+ }
+ if !elementFound {
+ t.Errorf("category not found: %+v", cat)
+ }
+ }
+}