From cd1ff4420481742db699dee59196308891abf6f1 Mon Sep 17 00:00:00 2001 From: Jean-Marcel Belmont Date: Mon, 20 Mar 2017 18:02:57 -0400 Subject: [PATCH] Add conditionals go file and call functions top down in workshop_test go file. --- workshop.go => assert.go | 0 conditionals.go | 63 ++++++++++++++++++++++++++++++++++++++++ variables_test.go | 7 ----- workshop_test.go | 13 +++++++++ 4 files changed, 76 insertions(+), 7 deletions(-) rename workshop.go => assert.go (100%) create mode 100644 conditionals.go delete mode 100644 variables_test.go create mode 100644 workshop_test.go diff --git a/workshop.go b/assert.go similarity index 100% rename from workshop.go rename to assert.go diff --git a/conditionals.go b/conditionals.go new file mode 100644 index 0000000..8e7a1b3 --- /dev/null +++ b/conditionals.go @@ -0,0 +1,63 @@ +package workshop + +import ( + "math" + "strconv" +) + +func conditionals() { + var str string + flag := true + + if flag { + str = "Righteous Path" + } + assert(str == "Righteous Path") + + var value int + if value < 10 { + value = 10 + } + assert(value == 10) + + value2 := 7 + if value2 > 10 { + value2++ + } else { + value2-- + } + assert(value2 == 6) + + const movie = "Rocky" + var score int + if movie == "Rambo" { + score = 9 + } else if movie == "Rocky" { + score = 10 + } else { + score = 6 + } + assert(score == 10) + + const food = "Pizza" + var drink string + switch food { + case "Fries": + drink = "Coke" + case "Sandwich": + drink = "Sprite" + default: + drink = "Milkshake" + } + assert(drink == "Milkshake") + + rem := math.Mod(6, 5) == 1 + assert(rem == true) + + num := "5" + otherNum, err := strconv.Atoi(num) + if err == nil { + otherNum-- + } + assert(otherNum == 4) +} diff --git a/variables_test.go b/variables_test.go deleted file mode 100644 index a1317fc..0000000 --- a/variables_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package workshop - -import "testing" - -func TestVariables(t *testing.T) { - variables() -} diff --git a/workshop_test.go b/workshop_test.go new file mode 100644 index 0000000..9cb5e6a --- /dev/null +++ b/workshop_test.go @@ -0,0 +1,13 @@ +package workshop + +import ( + "fmt" + "testing" +) + +func TestConditionals(t *testing.T) { + variables() + conditionals() + + fmt.Printf("\n%c[32;1mCongratulations you completed the Workshop!!!%c[0m\n\n", 27, 27) +}