Created
August 4, 2014 20:22
-
-
Save joellusky/3c113a279b40235823be 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
module WyncodeMethods | |
def self.convert_the_letter_A_into_a_Fixnum(s, *rest) | |
s.to_i if s.respond_to? :to_i | |
end | |
def self.convert_to_interger(n, *rest) | |
n.to_i if n.respond_to? :to_i | |
end | |
def self.Write_the_expression_1_plus_1_in_two_different_but_equal_ways(left, right) | |
left + right | |
end | |
def self.flatten_array(array, *rest) | |
array.flatten if array.respond_to? :flatten | |
end | |
def self.compare_strings(str1, str2, *rest) | |
if str1.is_a?(String) and str2.is_a?(String) | |
if str2 > str1 | |
-1 | |
elsif str2 == str1 | |
0 | |
else | |
1 | |
end | |
end | |
end | |
end |
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
module WyncodeTests | |
def self.test_convert_the_letter_A_into_a_Fixnum | |
puts WyncodeMethods.convert_the_letter_A_into_a_Fixnum("A") == 0 | |
#only enter letters | |
end | |
def self.test_convert_to_interger | |
puts WyncodeMethods.convert_to_interger(33.50*100) == 3350 | |
puts WyncodeMethods.convert_to_interger("") == 0 | |
puts WyncodeMethods.convert_to_interger([]) == nil | |
puts WyncodeMethods.convert_to_interger({}) == nil | |
end | |
def self.test_Write_the_expression_1_plus_1_in_two_different_but_equal_ways | |
puts WyncodeMethods.Write_the_expression_1_plus_1_in_two_different_but_equal_ways(1, 1) == 2 | |
puts WyncodeMethods.Write_the_expression_1_plus_1_in_two_different_but_equal_ways(1.0, 1) == 2 | |
end | |
def self.test_flatten_array | |
puts WyncodeMethods.flatten_array([[1,2,3],[:a,:b,:c]]) == [1,2,3,:a,:b,:c] | |
puts WyncodeMethods.flatten_array("").nil? | |
puts WyncodeMethods.flatten_array({}) == [] | |
puts WyncodeMethods.flatten_array(3,4,5).nil? | |
end | |
def self.test_compare_strings | |
puts WyncodeMethods.compare_strings("A","a") == -1 | |
puts WyncodeMethods.compare_strings("","") == 0 | |
puts WyncodeMethods.compare_strings("a","A") == 1 | |
puts WyncodeMethods.compare_strings("nil","1") == 1 | |
puts WyncodeMethods.compare_strings(2,3).nil? | |
puts WyncodeMethods.compare_strings([],[]).nil? | |
puts WyncodeMethods.compare_strings({},{}).nil? | |
end | |
end |
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 "./wyncode_methods2.rb" | |
require "./wyncode_methods_tests.rb" | |
WyncodeTests.test_convert_the_letter_A_into_a_Fixnum | |
WyncodeTests.test_convert_to_interger | |
WyncodeTests.test_Write_the_expression_1_plus_1_in_two_different_but_equal_ways | |
WyncodeTests.test_flatten_array | |
WyncodeTests.test_compare_strings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment