GithubHelp home page GithubHelp logo

phase-3-metaprogramming-triangle-classification-lab's Introduction

Triangle Classification Lab

Learning Goals

  • Define a custom error class and use it

Instructions

Write a Triangle class that accepts three arguments on initialization. Each argument is a length of one of the three sides of the triangle.

Define an instance method, #kind that returns, as a symbol, its type. The valid types are:

  • :equilateral
  • :isosceles
  • :scalene

Triangle types

The #kind method should raise a custom error, TriangleError if the triangle is invalid. Check out the hint below to understand what makes a triangle valid.

Write a custom error class, TriangleError and inherit it from StandardError. This custom error class should be defined in the same file as the Triangle class, inside the Triangle class definition, like this:

# lib/triangle.rb

class Triangle
  # triangle code

  class TriangleError < StandardError
    # triangle error code
  end
end

Note: Several of the tests will be looking for the TriangleError to be raised. If you implement a rescue for it, however, the tests will not recognize that the error was raised. For purposes of this lab, therefore, you should not include a rescue.

Identifying Valid Triangles

A valid triangle must meet the following criteria:

  • Each side must be larger than 0.

  • The sum of the lengths of any two sides of a triangle always exceeds the length of the third side. This is a principle known as the triangle inequality.

Resources

phase-3-metaprogramming-triangle-classification-lab's People

Contributors

ahimmelstoss avatar aviflombaum avatar curiositypaths avatar deniznida avatar drakeltheryuujin avatar fislabstest avatar fs-lms-test-bot avatar gilmoursa avatar gj avatar ihollander avatar jmburges avatar juangongora avatar kthffmn avatar lizbur10 avatar loganhasson avatar maxwellbenton avatar realandrewcohn avatar sarogers avatar sophiedebenedetto avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phase-3-metaprogramming-triangle-classification-lab's Issues

Test For 'isoceles' Is Broken

Canvas Link

https://learning.flatironschool.com/courses/5286/assignments/172848?module_item_id=376680

Concern

This should not be failing:

class Triangle
  attr_accessor :equilateral, :isoceles, :scalene, :sides

  def initialize(side1, side2, side3)
    @side1 = side1
    @side2 = side2
    @side3 = side3
  end

  def kind()
    if @side1 == @side2 && @side2 == @side3 && @side1 == @side3
      :equilateral
    elsif @side1 == @side2 || @side2 == @side3 || @side1 == @side3
      :isoceles
    elsif @side1 != @side2 && @side2 != @side3 && @side1 != @side3
      :scalene
    else
      begin
        raise TriangleError
      end
    end
  end

  class TriangleError < StandardError
    def message()
      "The sum of the lengths of any two sides of a triangle must always exceeds the length of the third side."
    end
  end

end

equilateral_triangle = Triangle.new(2, 2, 2)

puts "equilateral_triangle: ", equilateral_triangle

Related Error Received:

Failures:

  1) Triangle#kind returns :isosceles when any two sides are equal
     Failure/Error: expect(Triangle.new(3, 4, 4).kind).to eq(:isosceles)
     
       expected: :isosceles
            got: :isoceles
     
       (compared using ==)
     
       Diff:
       @@ -1 +1 @@
       -:isosceles
       +:isoceles
       
     # ./spec/triangle_spec.rb:11:in `block (3 levels) in <top (required)>'

Additional Context

No response

Suggested Changes

No response

triangle inequality theorem

Canvas Link

https://learning.flatironschool.com/courses/5250/assignments/220470?module_item_id=513541

Concern

The sum of the lengths of any two sides of a triangle always exceeds the length of the third side. This is a principle known as the triangle inequality.

this is confusing a few of my students since they knew that wasn't the theorem, not sure if we want to change this.

Additional Context

https://www.britannica.com/science/triangle-inequality

Suggested Changes

  • technically this isn't correct, a student was confused by this, should we alter the phrase to be:

The sum of the lengths of any two sides of a triangle always equals or exceeds the length of the third side. This is a principle known as the triangle inequality.

the test would also need updated.

Solution to lab inconsistent with lessons provided

Canvas Link

https://learning.flatironschool.com/courses/5208/assignments/199424?module_item_id=451106

Concern

As a preface, this is an ongoing issue with many lessons and labs in this curriculum:

In working on the Triangle Classification Lab, I'm tasked with creating custom errors that triggered when certain arguments are passed.

The solution code to this lab demonstrates several strategies that are in no way laid out in the Canvas lessons intended to introduce the concepts of custom errors.

What am I to do? I've been warned time and again by technical coaches and instructors to never blindly copy + paste code that I don't comprehend. But the learning material isn't providing me with the tools to comprehend the acceptable answer.

Additional Context

def validate_triangle raise TriangleError unless sides_greater_than_zero? && valid_triangle_inequality? end

nowhere in the preceding lesson does the lesson literature suggest the above strategy of housing custom errors in its own instance method.

Suggested Changes

Update the curriculum to set up your student body for success.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.