refactor: move issue #1370 regression tests to _demo/go
Move the three regression test cases from _demo/ to _demo/go/: - issue1370_gotypes (go/types.Object test) - issue1370_goast (go/ast.Expr test) - issue1370_geometry (custom interface test) Updated import path in geometry.go to reflect new location. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
This commit is contained in:
26
_demo/go/issue1370_geometry/geometry/geometry.go
Normal file
26
_demo/go/issue1370_geometry/geometry/geometry.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package geometry
|
||||
|
||||
type Shape interface {
|
||||
Area() float64
|
||||
validate() bool
|
||||
setID(int)
|
||||
}
|
||||
|
||||
type Rectangle struct {
|
||||
Width, Height float64
|
||||
id int
|
||||
}
|
||||
|
||||
func (r *Rectangle) Area() float64 { return r.Width * r.Height }
|
||||
func (r *Rectangle) validate() bool { return r.Width > 0 && r.Height > 0 }
|
||||
func (r *Rectangle) setID(id int) { r.id = id }
|
||||
func (r *Rectangle) GetID() int { return r.id }
|
||||
|
||||
func NewRectangle(width, height float64) *Rectangle {
|
||||
return &Rectangle{Width: width, Height: height}
|
||||
}
|
||||
|
||||
func RegisterShape(s Shape, id int) error {
|
||||
s.setID(id)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user