From c3715afba14885fd96f6f97a15d0b67ed5ec1c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Fri, 7 Oct 2022 15:06:04 +0900 Subject: [PATCH 01/20] initial commit --- go/study/base/go.mod | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 go/study/base/go.mod diff --git a/go/study/base/go.mod b/go/study/base/go.mod new file mode 100644 index 00000000..6792fc39 --- /dev/null +++ b/go/study/base/go.mod @@ -0,0 +1,3 @@ +module github.com/tecyokomichi/WebAppLearning/go/study/base + +go 1.16 From 194834bdc3bb00264a71542c1271e4135d23c9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 11:25:13 +0900 Subject: [PATCH 02/20] =?UTF-8?q?:+1:=20=E6=A7=8B=E9=80=A0=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 go/study/base/main.go diff --git a/go/study/base/main.go b/go/study/base/main.go new file mode 100644 index 00000000..266ece8c --- /dev/null +++ b/go/study/base/main.go @@ -0,0 +1,17 @@ +package main + +type Point struct { + Px int + Py int +} + +type Circle struct { + radius int + Point *Point +} + +type Rect struct { + width int + length int + Point *Point +} From 1077293b43ab4dfc7a8232c20d90da45c077b3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 11:30:26 +0900 Subject: [PATCH 03/20] =?UTF-8?q?:+1:=20=E5=87=BA=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/go/study/base/main.go b/go/study/base/main.go index 266ece8c..01ad504d 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -1,5 +1,7 @@ package main +import "fmt" + type Point struct { Px int Py int @@ -15,3 +17,21 @@ type Rect struct { length int Point *Point } + +func main() { + p1 := new(Point) + p1.Px = 100 + p1.Py = 50 + fmt.Printf("%#v\n", p1) + + c1 := new(Circle) + c1.Point = p1 + c1.radius = 30 + fmt.Printf("%#v\n", c1) + + r1 := new(Rect) + r1.Point = p1 + r1.width = 20 + r1.length = 10 + fmt.Printf("%#v\n", r1) +} From 9132853ca75ebc3dd756c9b2d460420cd9ed9a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 11:37:45 +0900 Subject: [PATCH 04/20] =?UTF-8?q?:sparkles:=20=E6=A7=8B=E9=80=A0=E6=8A=BD?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 16 ---------------- go/study/base/struct.go | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 go/study/base/struct.go diff --git a/go/study/base/main.go b/go/study/base/main.go index 01ad504d..8053dee3 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -2,22 +2,6 @@ package main import "fmt" -type Point struct { - Px int - Py int -} - -type Circle struct { - radius int - Point *Point -} - -type Rect struct { - width int - length int - Point *Point -} - func main() { p1 := new(Point) p1.Px = 100 diff --git a/go/study/base/struct.go b/go/study/base/struct.go new file mode 100644 index 00000000..d0f655a3 --- /dev/null +++ b/go/study/base/struct.go @@ -0,0 +1,17 @@ +package main + +type Point struct { + Px int + Py int +} + +type Circle struct { + radius int + Point *Point +} + +type Rect struct { + width int + length int + Point *Point +} \ No newline at end of file From e2ded0c034e228a97541110c7c195bcc7fa7e517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 11:48:41 +0900 Subject: [PATCH 05/20] =?UTF-8?q?:recycle:=20new=20=E2=86=92=20&?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 13 +++---------- go/study/base/struct.go | 10 ++++------ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/go/study/base/main.go b/go/study/base/main.go index 8053dee3..c35aa5bd 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -3,19 +3,12 @@ package main import "fmt" func main() { - p1 := new(Point) - p1.Px = 100 - p1.Py = 50 + p1 := &Point{Px: 100, Py: 50} fmt.Printf("%#v\n", p1) - c1 := new(Circle) - c1.Point = p1 - c1.radius = 30 + c1 := &Circle{Point: p1, radius: 30} fmt.Printf("%#v\n", c1) - r1 := new(Rect) - r1.Point = p1 - r1.width = 20 - r1.length = 10 + r1 := &Rect{Point: p1, width: 20, length: 10} fmt.Printf("%#v\n", r1) } diff --git a/go/study/base/struct.go b/go/study/base/struct.go index d0f655a3..4b627729 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -1,17 +1,15 @@ package main type Point struct { - Px int - Py int + Px, Py int } type Circle struct { radius int - Point *Point + Point *Point } type Rect struct { - width int - length int - Point *Point + width, length int + Point *Point } \ No newline at end of file From dfd0bbe01584ad5eb26659fafe23298221dd69b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 12:00:14 +0900 Subject: [PATCH 06/20] =?UTF-8?q?:+1:=20NewCircle=20=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 2 +- go/study/base/struct.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go/study/base/main.go b/go/study/base/main.go index c35aa5bd..13b149a8 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -6,7 +6,7 @@ func main() { p1 := &Point{Px: 100, Py: 50} fmt.Printf("%#v\n", p1) - c1 := &Circle{Point: p1, radius: 30} + c1 := NewCircle(p1, 30) fmt.Printf("%#v\n", c1) r1 := &Rect{Point: p1, width: 20, length: 10} diff --git a/go/study/base/struct.go b/go/study/base/struct.go index 4b627729..a4bab89d 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -12,4 +12,8 @@ type Circle struct { type Rect struct { width, length int Point *Point -} \ No newline at end of file +} + +func NewCircle(p *Point, r int) *Circle { + return &Circle{Point: p, radius: r} +} From dbaa853edd1fc14a59e25373727e45befb4992d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 13:08:09 +0900 Subject: [PATCH 07/20] =?UTF-8?q?:+1:=20ExpandCircle=20=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 2 ++ go/study/base/struct.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/go/study/base/main.go b/go/study/base/main.go index 13b149a8..7d2fc0da 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -8,6 +8,8 @@ func main() { c1 := NewCircle(p1, 30) fmt.Printf("%#v\n", c1) + ExpandCircle(c1, 10) + fmt.Printf("%#v\n", c1) r1 := &Rect{Point: p1, width: 20, length: 10} fmt.Printf("%#v\n", r1) diff --git a/go/study/base/struct.go b/go/study/base/struct.go index a4bab89d..6b2f94aa 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -17,3 +17,7 @@ type Rect struct { func NewCircle(p *Point, r int) *Circle { return &Circle{Point: p, radius: r} } + +func ExpandCircle(c *Circle, dr int) { + c.radius += dr +} From 482d6ba032b1cdfd7fe41ae94cad7100882a2b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 13:29:11 +0900 Subject: [PATCH 08/20] =?UTF-8?q?:green=5Fheart:=20NewCircle=20=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 go/study/base/main_test.go diff --git a/go/study/base/main_test.go b/go/study/base/main_test.go new file mode 100644 index 00000000..26632e71 --- /dev/null +++ b/go/study/base/main_test.go @@ -0,0 +1,11 @@ +package main + +import "testing" + +func TestNewCircle(t *testing.T) { + p := &Point{Px: 100, Py: 200} + c := NewCircle(p, 300) + if c.radius != 300 { + t.FailNow() + } +} From c076bca726ebaa44dda2a9df3def82db55c48743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 13:30:58 +0900 Subject: [PATCH 09/20] =?UTF-8?q?:green=5Fheart:=20ExpandCircle=20?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/go/study/base/main_test.go b/go/study/base/main_test.go index 26632e71..8f42e6f9 100644 --- a/go/study/base/main_test.go +++ b/go/study/base/main_test.go @@ -9,3 +9,12 @@ func TestNewCircle(t *testing.T) { t.FailNow() } } + +func TestExpandCircle(t *testing.T) { + p := &Point{Px: 100, Py: 200} + c := NewCircle(p, 300) + ExpandCircle(c, 400) + if c.radius != 700 { + t.FailNow() + } +} From aeebb923ae51250ac222ed16d5e079d1709cc291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 14:26:03 +0900 Subject: [PATCH 10/20] =?UTF-8?q?:recycle:=20Circle=20=E3=81=AE=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89Expand=20=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 2 +- go/study/base/main_test.go | 2 +- go/study/base/struct.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go/study/base/main.go b/go/study/base/main.go index 7d2fc0da..fcaa841c 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -8,7 +8,7 @@ func main() { c1 := NewCircle(p1, 30) fmt.Printf("%#v\n", c1) - ExpandCircle(c1, 10) + c1.Expand(10) fmt.Printf("%#v\n", c1) r1 := &Rect{Point: p1, width: 20, length: 10} diff --git a/go/study/base/main_test.go b/go/study/base/main_test.go index 8f42e6f9..0a243e89 100644 --- a/go/study/base/main_test.go +++ b/go/study/base/main_test.go @@ -13,7 +13,7 @@ func TestNewCircle(t *testing.T) { func TestExpandCircle(t *testing.T) { p := &Point{Px: 100, Py: 200} c := NewCircle(p, 300) - ExpandCircle(c, 400) + c.Expand(400) if c.radius != 700 { t.FailNow() } diff --git a/go/study/base/struct.go b/go/study/base/struct.go index 6b2f94aa..b1aa20d7 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -18,6 +18,6 @@ func NewCircle(p *Point, r int) *Circle { return &Circle{Point: p, radius: r} } -func ExpandCircle(c *Circle, dr int) { +func (c *Circle) Expand(dr int){ c.radius += dr } From e498106dae25f04b96b672582cf0ef529b970ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 16:53:39 +0900 Subject: [PATCH 11/20] =?UTF-8?q?:+1:=20Area=20=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/struct.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/go/study/base/struct.go b/go/study/base/struct.go index b1aa20d7..78eb4e70 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -21,3 +21,19 @@ func NewCircle(p *Point, r int) *Circle { func (c *Circle) Expand(dr int){ c.radius += dr } + +func (r *Rect) Area() int { + return r.width * r.length +} + +type RecList []*Rect + +func (rl RecList) Biggest() *Rect { + var b *Rect + for _, r := range rl { + if b == nil || r.Area() > b.Area(){ + b = r + } + } + return b +} From 5339a710a2682baea94be08f4722d4e4cf53bc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 16:57:06 +0900 Subject: [PATCH 12/20] =?UTF-8?q?green=5Fheart=20Area=20=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/go/study/base/main_test.go b/go/study/base/main_test.go index 0a243e89..853d220e 100644 --- a/go/study/base/main_test.go +++ b/go/study/base/main_test.go @@ -18,3 +18,11 @@ func TestExpandCircle(t *testing.T) { t.FailNow() } } + +func TestArea(t *testing.T) { + p := &Point{Px: 100, Py: 200} + r := &Rect{Point: p, width: 300, length: 400} + if r.Area() != 120000 { + t.FailNow() + } +} From 2a3c3f5d92702f246ecf78de588bf82717393beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 17:00:12 +0900 Subject: [PATCH 13/20] =?UTF-8?q?:+1:=20Biggest=20=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/go/study/base/main.go b/go/study/base/main.go index fcaa841c..fae208a5 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -12,5 +12,10 @@ func main() { fmt.Printf("%#v\n", c1) r1 := &Rect{Point: p1, width: 20, length: 10} + r2 := &Rect{Point: p1, width: 30, length: 20} + r3 := &Rect{Point: p1, width: 40, length: 30} + r4 := &Rect{Point: p1, width: 50, length: 40} + r5 := &Rect{Point: p1, width: 10, length: 5} fmt.Printf("%#v\n", r1) + fmt.Printf("%#v\n", RecList([]*Rect{r1, r2, r3, r4, r5}).Biggest()) } From 0af22f834f895b19b7f5bc299c4eb1ea37f4e44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Tue, 11 Oct 2022 17:01:47 +0900 Subject: [PATCH 14/20] =?UTF-8?q?:green=5Fheart:=20Biggest=20=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/go/study/base/main_test.go b/go/study/base/main_test.go index 853d220e..b23cc5f0 100644 --- a/go/study/base/main_test.go +++ b/go/study/base/main_test.go @@ -26,3 +26,13 @@ func TestArea(t *testing.T) { t.FailNow() } } + +func TestBiggest(t *testing.T) { + p := &Point{Px: 100, Py: 200} + r1 := &Rect{Point: p, width: 300, length: 400} + r2 := &Rect{Point: p, width: 30, length: 40} + r3 := &Rect{Point: p, width: 3, length: 4} + if RecList([]*Rect{r1, r2, r3}).Biggest().Area() != 120000 { + t.FailNow() + } +} From a18c405a0a34d8cb030c1f7af8a2875188211598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Wed, 12 Oct 2022 13:18:00 +0900 Subject: [PATCH 15/20] =?UTF-8?q?:+1:=20interface=20Shape=20=E3=82=92?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/struct.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/go/study/base/struct.go b/go/study/base/struct.go index 78eb4e70..7debc885 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -4,6 +4,10 @@ type Point struct { Px, Py int } +type Shape interface { + Area() float64 +} + type Circle struct { radius int Point *Point From 5568f3eb8124d8089cf02ded63baaae2b8842045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Wed, 12 Oct 2022 13:20:15 +0900 Subject: [PATCH 16/20] =?UTF-8?q?Area=20=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/struct.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/go/study/base/struct.go b/go/study/base/struct.go index 7debc885..8426c27e 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -1,5 +1,7 @@ package main +import "math" + type Point struct { Px, Py int } @@ -26,8 +28,12 @@ func (c *Circle) Expand(dr int){ c.radius += dr } -func (r *Rect) Area() int { - return r.width * r.length +func (c *Circle) Area() float64 { + return float64(c.radius * c.radius) * math.Pi +} + +func (r *Rect) Area() float64 { + return float64(r.width * r.length) } type RecList []*Rect From a8c7e838710a0a0851171bcd5f720aeb93ba7a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Wed, 12 Oct 2022 13:27:33 +0900 Subject: [PATCH 17/20] =?UTF-8?q?Circle=E3=80=81Rect=20=E3=81=9D=E3=82=8C?= =?UTF-8?q?=E3=81=9E=E3=82=8C=E3=81=AE=20Area=20=E3=82=92=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go/study/base/main.go b/go/study/base/main.go index fae208a5..92b3723b 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -8,10 +8,12 @@ func main() { c1 := NewCircle(p1, 30) fmt.Printf("%#v\n", c1) + fmt.Printf("面積: %#v\n", c1.Area()) c1.Expand(10) fmt.Printf("%#v\n", c1) r1 := &Rect{Point: p1, width: 20, length: 10} + fmt.Printf("面積: %#v\n", r1.Area()) r2 := &Rect{Point: p1, width: 30, length: 20} r3 := &Rect{Point: p1, width: 40, length: 30} r4 := &Rect{Point: p1, width: 50, length: 40} From 8d83b51f7c4bf53adbefb979db68b8cf6e5de1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Wed, 12 Oct 2022 13:31:05 +0900 Subject: [PATCH 18/20] =?UTF-8?q?:+1:=20Shape=E3=80=81Biggest=20=E3=82=92?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/struct.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/go/study/base/struct.go b/go/study/base/struct.go index 8426c27e..448f1785 100644 --- a/go/study/base/struct.go +++ b/go/study/base/struct.go @@ -47,3 +47,15 @@ func (rl RecList) Biggest() *Rect { } return b } + +type Shapes []Shape + +func (sha Shapes) Biggest() Shape { + var b Shape + for _, r := range sha { + if b == nil || r.Area() > b.Area(){ + b = r + } + } + return b +} From 2bb1c5350ea8c73ba056ee393f63c194c135dac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Wed, 12 Oct 2022 13:35:37 +0900 Subject: [PATCH 19/20] =?UTF-8?q?:+1:=20Shapes=20=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/go/study/base/main.go b/go/study/base/main.go index 92b3723b..1aa29b2c 100644 --- a/go/study/base/main.go +++ b/go/study/base/main.go @@ -20,4 +20,5 @@ func main() { r5 := &Rect{Point: p1, width: 10, length: 5} fmt.Printf("%#v\n", r1) fmt.Printf("%#v\n", RecList([]*Rect{r1, r2, r3, r4, r5}).Biggest()) + fmt.Printf("%#v\n", Shapes([]Shape{c1, r1, r2, r3, r4, r5}).Biggest()) } From 7721b1e9d7832d75564671238c3f9f28b3ea714c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BE=86=EF=BD=AC=EF=BD=A7=EF=BD=A7=EF=BD=A7-=E2=95=AC?= =?UTF-8?q?=E2=95=AC=28=E2=95=AC=5E=E0=B2=A0=EF=BD=98=E0=B2=A0=29=E2=99=AD?= Date: Wed, 12 Oct 2022 13:49:47 +0900 Subject: [PATCH 20/20] =?UTF-8?q?green=5Fheart=20Shapes=20Biggest=20?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/study/base/main_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/go/study/base/main_test.go b/go/study/base/main_test.go index b23cc5f0..859e9d68 100644 --- a/go/study/base/main_test.go +++ b/go/study/base/main_test.go @@ -29,10 +29,14 @@ func TestArea(t *testing.T) { func TestBiggest(t *testing.T) { p := &Point{Px: 100, Py: 200} + c := NewCircle(p, 300) r1 := &Rect{Point: p, width: 300, length: 400} r2 := &Rect{Point: p, width: 30, length: 40} r3 := &Rect{Point: p, width: 3, length: 4} if RecList([]*Rect{r1, r2, r3}).Biggest().Area() != 120000 { t.FailNow() } + if Shapes([]Shape{c, r1, r2, r3}).Biggest().Area() < 282743 || Shapes([]Shape{c, r1, r2, r3}).Biggest().Area() > 282744 { + t.FailNow() + } }