Created
September 10, 2020 07:46
-
-
Save macuk/25120a90207111c3319ed267f3c024a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class ArcTest < ActiveSupport::TestCase | |
test 'arguments are valid' do | |
assert_raises(ArgumentError) { Arc.new(0, 400) } | |
assert_raises(ArgumentError) { Arc.new(-10, 200) } | |
assert_raises(ArgumentError) { Arc.new(0, 360) } | |
assert_nothing_raised { Arc.new(0, 90) } | |
end | |
test 'to_s' do | |
assert_equal '360 degrees from 0 to 0', Arc.new(0, 0).to_s | |
assert_equal '360 degrees from 30 to 30', Arc.new(30, 30).to_s | |
assert_equal '90 degrees from 90 to 180', Arc.new(90, 180).to_s | |
assert_equal '60 degrees from 330 to 30', Arc.new(330, 30).to_s | |
end | |
test 'arc' do | |
assert_equal 360, Arc.new(0, 0).arc | |
assert_equal 360, Arc.new(30, 30).arc | |
assert_equal 90, Arc.new(90, 180).arc | |
assert_equal 60, Arc.new(330, 30).arc | |
end | |
test 'visible?' do | |
arc = Arc.new(0, 0) | |
[0, 90, 180, 270, 359.5].each { |angle| assert arc.visible?(angle) } | |
arc = Arc.new(30, 90) | |
[30, 50, 70, 90].each { |angle| assert arc.visible?(angle) } | |
[0, 100, 180, 270, 359.5].each { |angle| refute arc.visible?(angle) } | |
arc = Arc.new(330, 30) | |
[330, 340, 359, 0, 1, 20, 30].each { |angle| assert arc.visible?(angle) } | |
[31, 90, 180, 270, 329].each { |angle| refute arc.visible?(angle) } | |
end | |
test 'invalid angle in visible?' do | |
arc = Arc.new(0, 90) | |
assert_raises(ArgumentError) { arc.visible?(400) } | |
assert_raises(ArgumentError) { arc.visible?(360) } | |
assert_raises(ArgumentError) { arc.visible?(-10) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment