From 07912fc746947308d23d02d7a3787aab4eee68e0 Mon Sep 17 00:00:00 2001 From: Spiegel Date: Sat, 14 Jan 2023 16:02:23 +0900 Subject: [PATCH] Add Kan10.Direction method --- .github/workflows/vulns.yml | 4 ++-- README.md | 4 ++-- Taskfile.yml | 2 +- sample/sample3.go | 4 ++-- zodiac/zodiac.go | 18 ++++++++++++++++-- zodiac/zodiac_test.go | 38 +++++++++++++++++++++++-------------- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/.github/workflows/vulns.yml b/.github/workflows/vulns.yml index fb3a4cc..af80b13 100644 --- a/.github/workflows/vulns.yml +++ b/.github/workflows/vulns.yml @@ -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 diff --git a/README.md b/README.md index 879847b..fabe740 100644 --- a/README.md +++ b/README.md @@ -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) } @@ -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 丁丑 ``` diff --git a/Taskfile.yml b/Taskfile.yml index 0080bd1..b59a3f6 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -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' diff --git a/sample/sample3.go b/sample/sample3.go index eadf964..f40039b 100644 --- a/sample/sample3.go +++ b/sample/sample3.go @@ -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. diff --git a/zodiac/zodiac.go b/zodiac/zodiac.go index dc2b1be..58b8fdb 100644 --- a/zodiac/zodiac.go +++ b/zodiac/zodiac.go @@ -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 ( @@ -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. diff --git a/zodiac/zodiac_test.go b/zodiac/zodiac_test.go index 3fa5123..bd04bde 100644 --- a/zodiac/zodiac_test.go +++ b/zodiac/zodiac_test.go @@ -10,20 +10,22 @@ 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 { @@ -31,6 +33,14 @@ func TestKan10(t *testing.T) { 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) + } } } @@ -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.