Skip to content

Commit

Permalink
Merge pull request #12 from goark/debug-and-refactoring
Browse files Browse the repository at this point in the history
Add Kan10.Direction method
  • Loading branch information
spiegel-im-spiegel authored Jan 14, 2023
2 parents 0568f23 + 07912fc commit e3f2835
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/vulns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
name: Vulnerability scanner
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ^1.19
- name: install depm
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func main() {
continue
}
kan, shi := zodiac.ZodiacYearNumber(t.Year())
fmt.Printf("Year %v is %v%v\n", t.Year(), kan, shi)
fmt.Printf("Year %v is %v%v (Eho: %v)\n", t.Year(), kan, shi, kan.DirectionJp())
kan, shi = zodiac.ZodiacDayNumber(t)
fmt.Printf("Day %v is %v%v\n", t.Format("2006-01-02"), kan, shi)
}
Expand All @@ -219,7 +219,7 @@ func main() {

```
$ go run sample/sample3.go 2021-07-28
Year 2021 is 辛丑
Year 2021 is 辛丑 (Eho: 南南東微南)
Day 2021-07-28 is 丁丑
```

Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tasks:
cmds:
- go mod verify
- go test -shuffle on ./...
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.48.0 golangci-lint run --enable gosec --timeout 3m0s ./...
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.50.1 golangci-lint run --enable gosec --timeout 3m0s ./...
sources:
- ./go.mod
- '**/*.go'
Expand Down
4 changes: 2 additions & 2 deletions sample/sample3.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func main() {
continue
}
kan, shi := zodiac.ZodiacYearNumber(t.Year())
fmt.Printf("Year %v is %v%v\n", t.Year(), kan, shi)
fmt.Printf("Year %v is %v%v (Eho: %v)\n", t.Year(), kan, shi, kan.DirectionJp())
kan, shi = zodiac.ZodiacDayNumber(t)
fmt.Printf("Day %v is %v%v\n", t.Format("2006-01-02"), kan, shi)
}
}

/* Copyright 2021-2022 Spiegel
/* Copyright 2021-2023 Spiegel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
18 changes: 16 additions & 2 deletions zodiac/zodiac.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ const (
KanMax
)

var kanNames = [KanMax]string{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
var (
kanNames = [KanMax]string{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
kanDirection = [KanMax]int{75, 255, 165, 345, 165, 75, 255, 165, 345, 165}
kanDirectionJp = [KanMax]string{"東北東微東", "西南西微西", "南南東微南", "北北西微北", "南南東微南", "東北東微東", "西南西微西", "南南東微南", "北北西微北", "南南東微南"}
)

func (k Kan10) String() string {
return kanNames[k%KanMax]
}

// Direction mehtod reterns Eho (favourable direction).
func (k Kan10) Direction() int {
return kanDirection[k%KanMax]
}

// DirectionJp mehtod reterns japanese Eho (favourable direction) name.
func (k Kan10) DirectionJp() string {
return kanDirectionJp[k%KanMax]
}

type Shi12 uint

const (
Expand Down Expand Up @@ -83,7 +97,7 @@ func ZodiacYearNumber(y int) (Kan10, Shi12) {
return Kan10(k), Shi12(s)
}

/* Copyright 2021-2022 Spiegel
/* Copyright 2021-2023 Spiegel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
38 changes: 24 additions & 14 deletions zodiac/zodiac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ import (

func TestKan10(t *testing.T) {
testCases := []struct {
kan zodiac.Kan10
name string
kan zodiac.Kan10
name string
dir int
dirJp string
}{
{kan: zodiac.Kinoe, name: "甲"},
{kan: zodiac.Kinoto, name: "乙"},
{kan: zodiac.Hinoe, name: "丙"},
{kan: zodiac.Hinoto, name: "丁"},
{kan: zodiac.Tsutinoe, name: "戊"},
{kan: zodiac.Tsutinoto, name: "己"},
{kan: zodiac.Kanoe, name: "庚"},
{kan: zodiac.Kanoto, name: "辛"},
{kan: zodiac.Mizunoe, name: "壬"},
{kan: zodiac.Mizunoto, name: "癸"},
{kan: zodiac.Kan10(10), name: "甲"},
{kan: zodiac.Kinoe, name: "甲", dir: 75, dirJp: "東北東微東"},
{kan: zodiac.Kinoto, name: "乙", dir: 255, dirJp: "西南西微西"},
{kan: zodiac.Hinoe, name: "丙", dir: 165, dirJp: "南南東微南"},
{kan: zodiac.Hinoto, name: "丁", dir: 345, dirJp: "北北西微北"},
{kan: zodiac.Tsutinoe, name: "戊", dir: 165, dirJp: "南南東微南"},
{kan: zodiac.Tsutinoto, name: "己", dir: 75, dirJp: "東北東微東"},
{kan: zodiac.Kanoe, name: "庚", dir: 255, dirJp: "西南西微西"},
{kan: zodiac.Kanoto, name: "辛", dir: 165, dirJp: "南南東微南"},
{kan: zodiac.Mizunoe, name: "壬", dir: 345, dirJp: "北北西微北"},
{kan: zodiac.Mizunoto, name: "癸", dir: 165, dirJp: "南南東微南"},
{kan: zodiac.Kan10(10), name: "甲", dir: 75, dirJp: "東北東微東"},
}

for _, tc := range testCases {
str := tc.kan.String()
if str != tc.name {
t.Errorf("zodiac.Kan10(%v) is \"%v\", want %v", uint(tc.kan), str, tc.name)
}
dir := tc.kan.Direction()
if dir != tc.dir {
t.Errorf("zodiac.Kan10(%v) is \"%v\", want %v", uint(tc.kan), dir, tc.dir)
}
dirJp := tc.kan.DirectionJp()
if dirJp != tc.dirJp {
t.Errorf("zodiac.Kan10(%v) is \"%v\", want %v", uint(tc.kan), dirJp, tc.dirJp)
}
}
}

Expand Down Expand Up @@ -96,7 +106,7 @@ func TestZodiac(t *testing.T) {
}
}

/* Copyright 2021-2022 Spiegel
/* Copyright 2021-2023 Spiegel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit e3f2835

Please sign in to comment.