triangle

package
v0.0.0-...-543a44c Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: GPL-3.0 Imports: 1 Imported by: 0

README

Triangle

Determine if a triangle is equilateral, isosceles, or scalene.

An equilateral triangle has all three sides the same length.

An isosceles triangle has at least two sides the same length. (It is sometimes specified as having exactly two sides the same length, but for the purposes of this exercise we'll say at least two.)

A scalene triangle has all sides of different lengths.

Note

For a shape to be a triangle at all, all sides have to be of length > 0, and the sum of the lengths of any two sides must be greater than or equal to the length of the third side. See Triangle Inequality.

Dig Deeper

The case where the sum of the lengths of two sides equals that of the third is known as a degenerate triangle - it has zero area and looks like a single line. Feel free to add your own code/tests to check for degenerate triangles.

Constant Declarations

In this exercise you are asked to declare a series of constants used to identify different types of triangles. Pick the data type you think works best for this and get the tests passing.

Afterwards, it may be worth reading about Go's predeclared identifier iota. There's an excellent write up about it here.

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 and --benchmem flags:

go test -v --bench . --benchmem

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

The Ruby Koans triangle project, parts 1 & 2 http://rubykoans.com

Submitting Incomplete Solutions

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

Documentation

Overview

Package triangle should have a package comment that summarizes what it's about. https://golang.org/doc/effective_go.html#commentary

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind is a triangle type Notice KindFromSides() returns this type. Pick a suitable data type.

const (
	// NaT not a triangle
	NaT Kind = iota
	// Equ equilateral
	Equ Kind = iota
	// Iso isosceles
	Iso Kind = iota
	// Sca scalene
	Sca Kind = iota
)

func KindFromSides

func KindFromSides(a, b, c float64) Kind

KindFromSides should have a comment documenting it.

Jump to

Keyboard shortcuts

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