forked from rabajaj0509/Ruby-concepts-step-by-step
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write test cases for multipy program and vowel checker
- Loading branch information
1 parent
88792a2
commit 3a6aaa7
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'minitest/autorun' | ||
|
||
module MiniTest::Assertions | ||
def assert_vowel(letter) | ||
assert %w(a e i o u).include?(letter), "Expected #{letter} to be a vowel" | ||
end | ||
end | ||
|
||
describe 'Vowel Checker' do | ||
%w(a e i o u).each do |letter| | ||
it "#{letter} is a vowel" do | ||
assert_vowel letter | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class String | ||
def vowel? | ||
%w(a e i o u).include?(self) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Multiply | ||
def multiply(x, y) | ||
x * y | ||
end | ||
|
||
def multi_multiply(number) | ||
total = 1 | ||
if number == 0 | ||
puts 'Can not find a valid multiple' | ||
else | ||
(1..number).each do |i| | ||
total *= i | ||
end | ||
end | ||
total | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'minitest/autorun' | ||
require_relative 'multiply' | ||
|
||
class MutiplyTest < Minitest::Test | ||
def test_multiplication | ||
operation = Multiply.new | ||
result = operation.multiply(3, 3) | ||
assert_equal 9, result | ||
end | ||
|
||
def test_mutiplication_of_n_numbers | ||
nnumbers = Multiply.new | ||
result = nnumbers.multi_multiply(8) | ||
assert_equal 40320, result | ||
end | ||
end |