clock

package
v0.0.0-...-427ddc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 1 Imported by: 0

README

Clock

Implement a clock that handles times without dates.

You should be able to add and subtract minutes to it.

Two clocks that represent the same time should be equal to each other.

Running the tests

To run the tests run the command go test from within the exercise directory.

If the test suite contains benchmarks, you can run these with the -bench flag:

go test -bench .

Keep in mind that each reviewer will run benchmarks on a different machine, with different specs, so the results from these benchmark tests may vary.

Further information

For more detailed information about the Go track, including how to get help if you're having trouble, please visit the exercism.io Go language page.

Source

Pairing session with Erin Drummond https://twitter.com/ebdrummond

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock int
Example (Compare)
// a new clock
clock1 := New(10, 30)

// a second clock, same as the first
clock2 := New(10, 30)

// are the clocks equal?
fmt.Println(clock2 == clock1)

// change the second clock
clock2 = clock2.Add(30)

// are the clocks equal now?
fmt.Println(clock2 == clock1)
Output:

true
false
Example (New)
// a new clock
clock1 := New(10, 30)
fmt.Println(clock1.String())
Output:

10:30

func New

func New(h, m int) Clock

func (Clock) Add

func (c Clock) Add(m int) Clock
Example (Add)
// create a clock
clock := New(10, 30)

// add 30 minutes to it
clock = clock.Add(30)
fmt.Println(clock.String())
Output:

11:00
Example (Subtract)
// create a clock
clock := New(10, 30)

// subtract an hour and a half from it
clock = clock.Add(-90)
fmt.Println(clock.String())
Output:

09:00

func (Clock) String

func (c Clock) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL