Skip to content

Commit

Permalink
add builder test
Browse files Browse the repository at this point in the history
  • Loading branch information
senghoo committed Mar 19, 2016
1 parent 31fd4d2 commit 4cafe0a
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions 06_builder/builder_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 4cafe0a

Please sign in to comment.