Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- )
- type Point struct {
- x float64
- y float64
- }
- func NewPoint(x float64, y float64) *Point {
- p := new(Point)
- p.SetX(x)
- p.SetY(y)
- return p
- }
- // The getter of x
- func (p *Point) X() float64 {
- return p.x
- }
- // The getter of y
- func (p *Point) Y() float64 {
- return p.y
- }
- // The setter of x
- func (p *Point) SetX(x float64) {
- p.x = x
- }
- // The setter of y
- func (p *Point) SetY(y float64) {
- p.y = y
- }
- func main() {
- p := NewPoint(0, 0)
- if !(p.X() == 0) {
- log.Fatal("Wrong value")
- }
- if !(p.Y() == 0) {
- log.Fatal("Wrong value")
- }
- p.SetX(3)
- p.SetY(4)
- if !(p.X() == 3.0) {
- log.Fatal("Wrong value")
- }
- if !(p.Y() == 4.0) {
- log.Fatal("Wrong value")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement