Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rspec test #40

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@ jobs:
- name: Run Norminette
run: make norm
build:
name: build + check allowed functions
runs-on: macos-12
name: check allowed functions
runs-on: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build push_swap
run: make
- name: Clean push_swap
run: make fclean
- name: Build checker
run: make bonus
- name: Build push_swap
run: make
- name: check allowed_functions
run: test/check_allowed_functions.sh
unit_test:
name: unit_test
runs-on: macos-12
runs-on: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -45,14 +41,16 @@ jobs:
- name: Unit test
run: make test
e2e_test:
runs-on: macos-12
runs-on: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build push_swap
run: make
- name: Build checker
run: make bonus
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
7 changes: 3 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ RSpec::Core::RakeTask.new(:test) do |task|
task.pattern = [
"test/e2e/spec/corner_cases_spec.rb",
"test/e2e/spec/error_cases_spec.rb",
"test/e2e/spec/checker_spec.rb",
]
end

RSpec::Core::RakeTask.new(:performance) do |task|
task.pattern = [
"test/e2e/spec/performance_spec.rb",
]
task(:performance) do
ruby "test/e2e/performance.rb"
end
20 changes: 20 additions & 0 deletions test/e2e/performance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require_relative "helper/command_helper"

size = 500
results = []

20.times do
input = (0...500).to_a.shuffle.map(&:to_s)
stdout, _stderr, _status = execute_push_swap(*input)
results << stdout.split("\n").count

print "\e[32m.\e[0m"
end

max_operations = results.max
min_operations = results.min
average_operations = results.sum / results.size.to_f

puts "\nFor size #{size}: Max: #{max_operations}, Min: #{min_operations}, Average: #{average_operations}"
19 changes: 19 additions & 0 deletions test/e2e/spec/checker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require_relative "../helper/command_helper"

describe("Performance test for push_swap") do
[5, 10, 50, 100, 200, 500, 1000].each do |size|
it "measures operations for random input of size #{size}" do
results = []
input = (0...size).to_a.shuffle.map(&:to_s)
stdout, _stderr, status = execute_push_swap(*input)
expect(status.exitstatus).to(eq(0))
results << stdout.split("\n").count

stdout, _stderr, status = execute_checker(*input)
expect(status.exitstatus).to(eq(0))
expect(stdout).to(eq("OK\n"))
end
end
end
26 changes: 0 additions & 26 deletions test/e2e/spec/performance_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions test/pain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ NBR_LINK=$( echo "$NBR" | tr ' ' ',' )
CMD_LINK=$( echo "$CMD" | sed -e"s/rra/g/g" -e"s/rrb/h/g" \
-e"s/rrr/i/g" -e"s/sa/a/g" -e"s/sb/b/g" -e"s/ss/c/g" \
-e"s/ra/d/g" -e"s/rb/e/g" -e"s/rr/f/g" -e"s/pa/j/g" -e"s/pb/k/g" | tr -d '\n')
# CMD_COUNT=${#CMD_LINK}
RESULT=$( echo $CMD | ./checker $NBR )
CMD_COUNT=${#CMD_LINK}
# RESULT=$( echo $CMD | ./checker $NBR )
echo "Operations: $CMD_COUNT"
echo "Result $RESULT"
open "https://kaaaaakun.github.io/push-swap-pain/?&nbr=$NBR_LINK&cmd=$CMD_LINK"