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>
27 lines
579 B
Go
27 lines
579 B
Go
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
|
|
}
|