-
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.
- Loading branch information
Showing
8 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
# fundamental-ruby | ||
# test | ||
|
||
## rspec ./test/chater[number]/lesson[number].rb |
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 |
---|---|---|
@@ -1 +1,10 @@ | ||
#Bài 1: Viết chươnɡ trình tìm số lớn nhất tronɡ 3 số thực ɑ, b, c | ||
|
||
def solution(a, b, c) | ||
max = a | ||
|
||
max = b if b > max | ||
max = c if c > max | ||
|
||
return max | ||
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
#Bài 2: Viết chươnɡ trình nhập 2 số thực, kiểm trɑ xem chúnɡ có cùnɡ dấu hɑy khônɡ | ||
|
||
def solution(a, b) | ||
return true if a * b >= 0 | ||
return false | ||
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 |
---|---|---|
@@ -1 +1,10 @@ | ||
#Bài 3: Viết chươnɡ trình ɡiải và biện luận phươnɡ trình bậc nhất ɑx + b = 0 | ||
|
||
def solution(a, b) | ||
return false if a == 0 | ||
|
||
x = 0 | ||
x = -b/a if b != 0 | ||
|
||
return x | ||
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 |
---|---|---|
@@ -1,10 +1,27 @@ | ||
#Bài 1: Tính S(n) = 1 + 2 + 3 + … + n | ||
require_relative '../../chapter2/lesson1' | ||
|
||
def solution(n) | ||
sum = 0 | ||
for i in 1..n do | ||
sum = sum + i | ||
RSpec.describe 'solution' do | ||
describe 'when all numbers are positive' do | ||
it 'returns the maximun number' do | ||
expect(solution(1, 2, 3)).to eq(3) | ||
expect(solution(4, 2, 1)).to eq(4) | ||
expect(solution(6, 8, 7)).to eq(8) | ||
end | ||
end | ||
|
||
describe 'when some numbers are negative' do | ||
it 'returns the maximum number' do | ||
expect(solution(-1, -2, -3)).to eq(-1) | ||
expect(solution(-4, -2, -1)).to eq(-1) | ||
expect(solution(-6, 8, 7)).to eq(8) | ||
end | ||
end | ||
|
||
describe 'when all numbers are negative' do | ||
it 'returns the maximum number' do | ||
expect(solution(-1, -2, -3)).to eq(-1) | ||
expect(solution(-4, -2, -1)).to eq(-1) | ||
expect(solution(-6, -8, -7)).to eq(-6) | ||
end | ||
end | ||
return sum | ||
end | ||
1 |
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
#Bài 2: Tính S(n) = 1^2 + 2^2 + … + n^2 | ||
require_relative '../../chapter2/lesson2' | ||
|
||
def solution(n) | ||
result = 0 | ||
for i in 1..n do | ||
result = result + i**2 | ||
RSpec.describe 'solution' do | ||
describe 'when both numbers have the same sign' do | ||
it 'returns true' do | ||
expect(solution(3.5, 2.7)).to eq(true) | ||
expect(solution(-3.5, -2.7)).to eq(true) | ||
expect(solution(0, 0)).to eq(true) | ||
end | ||
end | ||
|
||
describe 'when both numbers have different signs' do | ||
it 'returns false' do | ||
expect(solution(3.5, -2.7)).to eq(false) | ||
expect(solution(-3.5, 2.7)).to eq(false) | ||
end | ||
end | ||
return result | ||
end | ||
1 |
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 |
---|---|---|
@@ -1 +1,23 @@ | ||
1 | ||
require_relative '../../chapter2/lesson3' | ||
|
||
RSpec.describe 'solution' do | ||
describe 'when a is 0' do | ||
it 'returns false' do | ||
expect(solution(0, 5)).to eq(false) | ||
end | ||
end | ||
|
||
describe 'when b is 0' do | ||
it 'returns 0' do | ||
expect(solution(2, 0)).to eq(0) | ||
end | ||
end | ||
|
||
describe 'when a and b are not 0' do | ||
it 'returns the correct value of x' do | ||
expect(solution(2, 4)).to eq(-2) | ||
expect(solution(-3, -9)).to eq(-3) | ||
expect(solution(5, -15)).to eq(3) | ||
end | ||
end | ||
end |