Created
July 20, 2015 04:38
-
-
Save azechi/3f71deaf875484691a89 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
class Triangle | |
def self.hantei(a,b,c) | |
# 2辺を足した数が残り1辺"より小さい" | |
if(!(a < b + c && b < a + c && c < a + b)) | |
return '三角形じゃないです><' | |
end | |
if(a == b && b == c) | |
return '正三角形ですね!' | |
end | |
if(a == b || b == c || a == c) | |
return '二等辺三角形ですね!' | |
end | |
return '不等辺三角形ですね!' | |
end | |
end | |
# TODO テストの書き方 コマンドラインから引数をとる場合 | |
puts Triangle.hantei(*(ARGV.join.split(',').map {|s| s.to_i })) |
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_relative '../triangle' | |
describe Triangle do | |
# '正三角形ですね!' | |
# 長さなし | |
specify{ expect(Triangle.hantei(0,0,0)).to eq '三角形じゃないです><' } | |
# 長さあり | |
specify{ expect(Triangle.hantei(1,1,1)).to eq '正三角形ですね!' } | |
# '三角形じゃないです><' | |
# 2辺を足した数が残り1辺と等しいかそれ以上の場合は三角形ではない | |
# 2 + 3 > 4 OK | |
specify{ expect(Triangle.hantei(2,3,4)).to eq '不等辺三角形ですね!' } | |
specify{ expect(Triangle.hantei(2,4,3)).to eq '不等辺三角形ですね!' } | |
specify{ expect(Triangle.hantei(2,3,4)).to eq '不等辺三角形ですね!' } | |
specify{ expect(Triangle.hantei(2,4,3)).to eq '不等辺三角形ですね!' } | |
specify{ expect(Triangle.hantei(4,2,3)).to eq '不等辺三角形ですね!' } | |
specify{ expect(Triangle.hantei(4,3,2)).to eq '不等辺三角形ですね!' } | |
# 2 + 3 <= 5 NG | |
specify{ expect(Triangle.hantei(2,3,5)).to eq '三角形じゃないです><' } | |
specify{ expect(Triangle.hantei(2,5,3)).to eq '三角形じゃないです><' } | |
specify{ expect(Triangle.hantei(2,3,5)).to eq '三角形じゃないです><' } | |
specify{ expect(Triangle.hantei(2,5,3)).to eq '三角形じゃないです><' } | |
specify{ expect(Triangle.hantei(5,2,3)).to eq '三角形じゃないです><' } | |
specify{ expect(Triangle.hantei(5,3,2)).to eq '三角形じゃないです><' } | |
# '二等辺三角形ですね!' | |
# 2辺を足した数 < 残り | |
# a * 2 > b, a + b > a | |
# a = 3, b = 5 OK | |
specify{ expect(Triangle.hantei(3,3,5)).to eq '二等辺三角形ですね!' } | |
specify{ expect(Triangle.hantei(3,5,3)).to eq '二等辺三角形ですね!' } | |
specify{ expect(Triangle.hantei(5,3,3)).to eq '二等辺三角形ですね!' } | |
# a = 3, b = 6 NG | |
specify{ expect(Triangle.hantei(3,3,6)).to eq '三角形じゃないです><' } | |
specify{ expect(Triangle.hantei(3,6,3)).to eq '三角形じゃないです><' } | |
specify{ expect(Triangle.hantei(6,3,3)).to eq '三角形じゃないです><' } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment