From 98d984908ef8ff741a72d1720c121fcc6bc9a21a Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 21:12:05 +0900 Subject: [PATCH] update rspec test --- Rakefile | 1 + test/e2e/spec/checker_spec.rb | 19 +++++++++++++++++++ test/e2e/spec/performance_spec.rb | 6 +----- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/e2e/spec/checker_spec.rb diff --git a/Rakefile b/Rakefile index dbfcb05..460d3f8 100644 --- a/Rakefile +++ b/Rakefile @@ -6,6 +6,7 @@ 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 diff --git a/test/e2e/spec/checker_spec.rb b/test/e2e/spec/checker_spec.rb new file mode 100644 index 0000000..b9f6945 --- /dev/null +++ b/test/e2e/spec/checker_spec.rb @@ -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 diff --git a/test/e2e/spec/performance_spec.rb b/test/e2e/spec/performance_spec.rb index aff88f2..37baf4a 100644 --- a/test/e2e/spec/performance_spec.rb +++ b/test/e2e/spec/performance_spec.rb @@ -8,13 +8,9 @@ results = [] 20.times do input = (0...500).to_a.shuffle.map(&:to_s) - stdout, _stderr, status = execute_push_swap(*input) - expect(status.exitstatus).to(eq(0)) + stdout, _stderr, _status = execute_push_swap(*input) results << stdout.split("\n").count - stdout, _stderr, status = execute_checker(*input) - expect(status.exitstatus).to(eq(0)) - expect(stdout).to(eq("OK\n")) print "\e[32m.\e[0m" end max_operations = results.max