Skip to content

Commit

Permalink
value convert
Browse files Browse the repository at this point in the history
  • Loading branch information
DeyV committed Aug 29, 2013
1 parent ae9e5b5 commit 778302a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 27 deletions.
25 changes: 4 additions & 21 deletions board/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,32 @@ func TestPut_StoneOnUsedField_Panic(t *testing.T) {
assert.Panics(t, func() {
_ = b.Put(1, 1, WHITE)
})

}

func TestGetBreathCount_StoneOnEmptyField_Full(t *testing.T) {
b := NewBoard()

b.Put(1, 1, BLACK)

res := b.GetFieldBreatch(1, 1)

assert.Equal(t, 4, res)
}

func TestGetFieldBreatch_StoneOnTopField_3breath(t *testing.T) {
b := NewBoard()

b.Put(1, 0, BLACK)

res := b.GetFieldBreatch(1, 0)

assert.Equal(t, 3, res)
}

func TestGetFieldBreatch_StoneInCorner_1breath(t *testing.T) {
b := NewBoard()

b.Put(1, 0, BLACK)

res := b.GetFieldBreatch(0, 0)

assert.Equal(t, 1, res)
}

Expand All @@ -83,7 +82,6 @@ func TestGetFieldBreatch_SecondStoneClose_1BreathLess(t *testing.T) {
b.Put(2, 1, BLACK)

res := b.GetFieldBreatch(2, 1)

assert.Equal(t, 3, res)
assert.Equal(t, 3, b.Get(2, 1).breath)
}
Expand All @@ -98,7 +96,6 @@ func TestGetFieldBreatch_TopRowSecondStoneClose_1BreathLess(t *testing.T) {
b.Put(2, 0, BLACK)

res := b.GetFieldBreatch(2, 0)

assert.Equal(t, 2, res)
assert.Equal(t, 2, b.Get(2, 0).breath)
}
Expand All @@ -113,7 +110,6 @@ func TestPlayBoard_ToString_String(t *testing.T) {
b := NewBoard()

textInfo := b.String()

assert.NotEmpty(t, textInfo)
}

Expand All @@ -126,7 +122,6 @@ func TestPut_OneStoneInGroupOnEmptyField_GroupBreath(t *testing.T) {
b.Put(2, 2, BLACK)

res := b.Get(2, 2).Group.breath

assert.Equal(t, 4, res)
}

Expand All @@ -141,7 +136,6 @@ func TestPut_TwoStoneNextTo_OneGroup(t *testing.T) {

g1 := b.Get(2, 2).Group
g2 := b.Get(3, 2).Group

assert.Equal(t, g1, g2)
}

Expand All @@ -155,7 +149,6 @@ func TestPut_TwoStoneInGroupOnEmptyField_GroupBreath(t *testing.T) {
b.Put(3, 2, BLACK)

res := b.Get(2, 2).Group.breath

assert.Equal(t, 6, res)
}

Expand All @@ -175,9 +168,6 @@ func TestPut_TwoStoneInGroupOnTop_GroupBreath(t *testing.T) {
b.Put(3, 1, BLACK)

f2 := b.Get(3, 1)

// fmt.Println(b)

assert.Equal(t, 3, f2.breath)
assert.Equal(t, 6, f2.Group.breath)
}
Expand All @@ -192,7 +182,6 @@ func TestPut_TwoStoneInCornerWith_GroupBreath(t *testing.T) {
b.Put(1, 0, BLACK)

res := b.Get(1, 0).Group.breath

assert.Equal(t, 3, res)
}

Expand All @@ -207,7 +196,6 @@ func TestPut_TwoStoneInCornerWithNeightbour_GroupBreath(t *testing.T) {
b.Put(2, 0, WHITE)

res := b.Get(1, 0).Group.breath

assert.Equal(t, 2, res)
}

Expand All @@ -223,7 +211,6 @@ func TestPut_ThreeStoneInCornerWithNeightbour_GroupBreath(t *testing.T) {
b.Put(3, 0, WHITE)

res := b.Get(1, 0).Group.breath

assert.Equal(t, 3, res)
}

Expand All @@ -249,11 +236,7 @@ func TestPut_PutStoneAroundOtherInCorner_OtherDisaper(t *testing.T) {
b.Put(0, 1, BLACK)

res := b.Get(0, 0)
// fmt.Print(b.String())

if !res.IsEmpty() {
t.Error()
}
assert.True(t, res.IsEmpty())
}

/*
Expand Down
30 changes: 28 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func (g *OpenGame) PressBackspace() {
func (g *OpenGame) CheckKey(r rune, s int) bool {
size := rune(s)

if r >= 'a' && r < 'a'+size {
if r >= 'A' && r < 'A'+size {
return true
}

if r >= 'A' && r < 'A'+size {
if r >= 'a' && r < 'a'+size {
return true
}

Expand All @@ -76,6 +76,32 @@ func (g *OpenGame) CheckKey(r rune, s int) bool {
return false
}

func (g *OpenGame) convertValue(val string) (x, y int) {
var xx rune
var yy string

for _, r := range val {
if r >= 'a' {
xx = r - ('a' - 'A')
continue
}

if r >= 'A' {
xx = r
continue
}

// on big board it can will be bigger number then 9
if r >= '1' {
yy += string(r)
}
}

x = int(xx - 'A' + 1)
y, _ = strconv.Atoi(yy)
return
}

/*******************************************/

var FirstRow = 3
Expand Down
44 changes: 40 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var _ = testing.AllocsPerRun

func TestCheckKeys_Letters_True(t *testing.T) {
func TestOpenGame_CheckKeys_Letters_True(t *testing.T) {
game := &OpenGame{}
BoardSize := 9

Expand All @@ -16,25 +16,61 @@ func TestCheckKeys_Letters_True(t *testing.T) {
assert.True(t, game.CheckKey('i', BoardSize))
}

func TestCheckKeys_LetteresToBig_False(t *testing.T) {
func TestOpenGame_CheckKeys_LetteresToBig_False(t *testing.T) {
game := &OpenGame{}
BoardSize := 9

assert.False(t, game.CheckKey('j', BoardSize))
assert.False(t, game.CheckKey('z', BoardSize))
}

func TestCheckKeys_Numbers_True(t *testing.T) {
func TestOpenGame_CheckKeys_Numbers_True(t *testing.T) {
game := &OpenGame{}
BoardSize := 9

assert.True(t, game.CheckKey('1', BoardSize))
assert.True(t, game.CheckKey('2', BoardSize))
}

func TestCheckKeys_NumbersToBig_false(t *testing.T) {
func TestOpenGame_CheckKeys_NumbersToBig_false(t *testing.T) {
game := &OpenGame{}
BoardSize := 9

assert.False(t, game.CheckKey('0', BoardSize))
}

func TestOpenGame_convertValue_A2_Ok(t *testing.T) {
game := &OpenGame{}

x, y := game.convertValue("A2")

assert.Equal(t, 1, x)
assert.Equal(t, 2, y)
}

func TestOpenGame_convertValue_a2_Ok(t *testing.T) {
game := &OpenGame{}

x, y := game.convertValue("a2")

assert.Equal(t, 1, x)
assert.Equal(t, 2, y)
}

func TestOpenGame_convertValue_B3_Ok(t *testing.T) {
game := &OpenGame{}

x, y := game.convertValue("B3")

assert.Equal(t, 2, x)
assert.Equal(t, 3, y)
}

func TestOpenGame_convertValue_AA23_Ok(t *testing.T) {
game := &OpenGame{}

x, y := game.convertValue("AA23")

assert.Equal(t, 1, x)
assert.Equal(t, 23, y)
}

0 comments on commit 778302a

Please sign in to comment.