Created
May 11, 2018 08:05
-
-
Save kkismd/516a68b05f937528045a42cf0d15d367 to your computer and use it in GitHub Desktop.
steep example
This file contains hidden or 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 Temperature | |
# @implements Temperature | |
private_class_method :new | |
def self.celsius(num) | |
new(num) | |
end | |
def self.fahrenheit(num) | |
new(f2c(num)) | |
end | |
def self.f2c(f) | |
(f - 32) / 1.8 | |
end | |
def self.c2f(c) | |
c * 1.8 + 32 | |
end | |
# @type ivar @celsius: Numeric | |
def initialize(num) | |
@celsius = num | |
end | |
def celsius | |
@celsius | |
end | |
def celsius_label | |
"摂氏#{@celsius}度" | |
end | |
def fahrenheit | |
self.class.c2f(celsius) | |
end | |
def fahrenheit_label | |
"華氏#{fahrenheit}度" | |
end | |
end |
This file contains hidden or 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 Temperature | |
def (constructor) self.celsius: (Numeric) -> instance | |
def (constructor) self.fahrenheit: (Numeric) -> instance | |
def self.f2c: (any) -> Numeric | |
def self.c2f: (any) -> Numeric | |
def initialize: (Numeric) -> any | |
def celsius: -> Numeric | |
def celsius_label: -> String | |
def fahrenheit: -> Numeric | |
def fahrenheit_label: -> String | |
end | |
extension Class (X) | |
def private_class_method: (Symbol) -> any | |
end |
This file contains hidden or 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 'minitest/autorun' | |
require './temperature' | |
class TestTemperature < Minitest::Test | |
def test_celsius | |
subject = Temperature.celsius(34) | |
assert_equal subject.celsius, 34 | |
end | |
def test_zero | |
zero = Temperature.celsius(0) | |
assert_equal zero.fahrenheit, 32 | |
end | |
def test_zero2 | |
zero = Temperature.fahrenheit(32) | |
assert_equal zero.celsius, 0 | |
end | |
def test_handred | |
handred = Temperature.celsius(100) | |
assert_equal handred.fahrenheit, 212 | |
end | |
def test_handred2 | |
handred = Temperature.fahrenheit(212) | |
assert_equal handred.celsius, 100 | |
end | |
def test_fahrenheit | |
subject = Temperature.fahrenheit(12) | |
assert_equal subject.fahrenheit, 12 | |
end | |
def test_celsius_label | |
zero = Temperature.celsius(0) | |
assert_equal zero.celsius_label, "摂氏0度" | |
end | |
def test_celsius_label | |
zero = Temperature.celsius(0) | |
assert_equal zero.fahrenheit_label, "華氏32.0度" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
steep checkを実行してみると
NoMethodError
が出てしまう