From 4cafe0a84764b9ed2785d0617c167233bfca2346 Mon Sep 17 00:00:00 2001 From: Senghoo Kim Date: Sat, 19 Mar 2016 23:40:44 +0800 Subject: [PATCH] add builder test --- 06_builder/builder_test.go | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 06_builder/builder_test.go diff --git a/06_builder/builder_test.go b/06_builder/builder_test.go new file mode 100644 index 0000000..3f1e443 --- /dev/null +++ b/06_builder/builder_test.go @@ -0,0 +1,66 @@ +package builder + +import ( + "strconv" + "testing" +) + +type Builder1 struct { + result string +} + +func (b *Builder1) Part1() { + b.result += "1" +} + +func (b *Builder1) Part2() { + b.result += "2" +} + +func (b *Builder1) Part3() { + b.result += "3" +} + +func (b *Builder1) GetResult() string { + return b.result +} + +func TestBuilder1(t *testing.T) { + builder := &Builder1{} + director := NewDirector(builder) + director.Construct() + res := builder.GetResult() + if res != "123" { + t.Fatalf("Builder1 fail expect 123 acture %s", res) + } +} + +type Builder2 struct { + result int +} + +func (b *Builder2) Part1() { + b.result += 1 +} + +func (b *Builder2) Part2() { + b.result += 2 +} + +func (b *Builder2) Part3() { + b.result += 3 +} + +func (b *Builder2) GetResult() string { + return strconv.Itoa(b.result) +} + +func TestBuilder2(t *testing.T) { + builder := &Builder2{} + director := NewDirector(builder) + director.Construct() + res := builder.GetResult() + if res != "6" { + t.Fatalf("Builder2 fail expect 6 acture %s", res) + } +}