Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stock converter #137

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion annotate-samples.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
NUM_SAMPLE=789
NUM_SAMPLE=1148

SKIP_SAMPLES=(0)

Expand Down
7 changes: 6 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ type TestData struct {
HoujinExecutiveNames []string `yaml:"HoujinExecutiveNames"`
HoujinRepresentativeNames []string `yaml:"HoujinRepresentativeNames"`
HoujinCapital string `yaml:"HoujinCapital"`
HoujinStock string `yaml:"HoujinStock"`
HoujinCreatedAt string `yaml:"HoujinCreatedAt"`
HoujinBankruptedAt string `yaml:"HoujinBankruptedAt"`
HoujinDissolvedAt string `yaml:"HoujinDissolvedAt"`
HoujinContinuedAt string `yaml:"HoujinContinuedAt"`
}

func TestToukiboParser(t *testing.T) {
testCount := 1147
testCount := 1148

for i := 1; i <= testCount; i++ {
t.Run(fmt.Sprintf("test%d", i), func(t *testing.T) {
Expand Down Expand Up @@ -119,6 +120,10 @@ func TestToukiboParser(t *testing.T) {
t.Fatalf("capital is not match,\nwant : %s,\ngot : %d,", td.HoujinCapital, h.GetHoujinCapital())
}

if fmt.Sprint(h.GetHoujinStock()) != td.HoujinStock {
t.Fatalf("stock is not match,\nwant : %s,\ngot : %d,", td.HoujinStock, h.GetHoujinStock())
}

if h.GetHoujinCreatedAt() != td.HoujinCreatedAt {
t.Fatalf("created_at is not match,\nwant : %s,\ngot : %s,", td.HoujinCreatedAt, h.GetHoujinCreatedAt())
}
Expand Down
2 changes: 1 addition & 1 deletion toukibo/parse_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (h *HoujinBody) ConsumeHoujinCapital(s string) bool {
}

func (h *HoujinBody) ConsumeHoujinStock(s string) bool {
return strings.Contains(s, "発行済株式の総数")
return strings.HasPrefix(s, "発行済株式の総数")
}

func (h *HoujinBody) ConsumeHoujinToukiRecord(s string) bool {
Expand Down
11 changes: 9 additions & 2 deletions toukibo/stock_converter.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package toukibo

import "strings"
import (
"strings"
)

func StockToNumber(stock string) int {
// 発行済株式の総数5万株 → 50000
stock = strings.Replace(stock, "発行済株式の総数", "", -1)
if strings.HasPrefix(stock, "普通株式") { // sample1082用のハック
stock = strings.Replace(stock, "普通株式", "", -1)
}
stock = ZenkakuToHankaku(stock)

sums := 0
Expand All @@ -27,7 +32,9 @@ func StockToNumber(stock string) int {
cur = 0
case '株':
sums += cur
cur = 0
return sums
// 発行済株式の総数4万8249株各種の株式の数普通株式   3万249株A種優先株式 1万株B種優先株式 8000株
// のようなパターンでは最初の株でReturnさせる
}
}
return sums
Expand Down
5 changes: 5 additions & 0 deletions toukibo/stock_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func TestStockToNumber(t *testing.T) {
input: "発行済株式の総数5万株",
expected: 50000,
},
{
// sample1082
input: "発行済株式の総数普通株式     5138株A種優先株式   1250株B種優先株式   3250株",
expected: 5138,
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion toukibo/yen_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestYenToNumber(t *testing.T) {
expected: 1234000000000000,
},
{
input: "1234兆円1234億5678万9012円",
input: "1234兆1234億5678万9012円",
expected: 1234123456789012,
},
{
Expand Down
Loading