|
|
|
package main
|
|
|
|
|
|
|
|
import "github.com/01-edu/z01"
|
|
|
|
|
|
|
|
const CLOSE = 0
|
|
|
|
const OPEN = 1
|
|
|
|
|
|
|
|
type Door struct {
|
|
|
|
State int
|
|
|
|
}
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
func PrintStr(s string) {
|
|
|
|
for _, r := range s {
|
|
|
|
z01.PrintRune(r)
|
|
|
|
}
|
|
|
|
z01.PrintRune('\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
func CloseDoor(ptrDoor *Door) {
|
|
|
|
PrintStr("Door Closing...")
|
|
|
|
ptrDoor.State = CLOSE
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpenDoor(ptrdoor *Door) {
|
|
|
|
PrintStr("Door Opening...")
|
|
|
|
ptrdoor.State = OPEN
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsDoorOpened(ptrDoor *Door) bool {
|
|
|
|
PrintStr("is the Door opened ?")
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
return ptrDoor.State == OPEN
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsDoorClosed(ptrDoor *Door) bool {
|
|
|
|
PrintStr("is the Door closed ?")
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
return ptrDoor.State == CLOSE
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var door Door
|
|
|
|
|
|
|
|
OpenDoor(&door)
|
|
|
|
if IsDoorClosed(&door) {
|
|
|
|
OpenDoor(&door)
|
|
|
|
}
|
|
|
|
if IsDoorOpened(&door) {
|
|
|
|
CloseDoor(&door)
|
|
|
|
}
|
|
|
|
if door.State == OPEN {
|
|
|
|
CloseDoor(&door)
|
|
|
|
}
|
|
|
|
}
|