Created
June 5, 2020 21:01
-
-
Save lcowell/7af3660985d109d3bc78399ce248c5f3 to your computer and use it in GitHub Desktop.
Code from my bisect experiment
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 ListBisector | |
# anything that responds to call: block, lambda, method | |
# the function being called needs to perform a function against 2 bounded(eg. has length), enumerable objects(eg. has each) | |
def bisect(a, b, &block) | |
a_result = block.call(a) | |
b_result = block.call(b) | |
if a_result == b_result | |
puts "done: both sets are interesting or uninteresting, we're done" | |
[a, b] | |
elsif a_result | |
puts "next: splitting a" | |
bisect(first_half(a), second_half(a), &block) | |
elsif b_result | |
puts "next: splitting b" | |
bisect(first_half(b), second_half(b), &block) | |
else # bloth a_result and b_result are falsey | |
puts "done: both sets are falsey" | |
[a, b] | |
end | |
end | |
def first_half(list) | |
list[0..(list.length/2.0).floor] | |
end | |
def second_half(list) | |
list[(list.length/2.0).ceil..-1] | |
end | |
extend self | |
end | |
class GlobalStateSpecs | |
include ListBisector | |
def initialize(spec_path, seed: nil, files: nil) | |
@spec_path = spec_path | |
@seed = seed | |
@files = files # build list of all files? | |
end | |
def narrow_list | |
bisect(first_half(@files), second_half(@files)) do |files| | |
ap "considering #{files.length} files" | |
cmd = command(files) | |
puts "===========" | |
puts cmd | |
puts "===========" | |
result = system(cmd) | |
prompt | |
end | |
end | |
def command(files) | |
"./bin/bundle exec rspec --format=documentation --seed #{@seed} #{files.join(" ")} #{@spec_path}" | |
end | |
def prompt | |
puts | |
puts "(i)nteresting (u)nintersting" | |
response = STDIN.getch | |
if response == "i" | |
true | |
elsif response == "u" | |
false | |
else | |
"#{response} is not understood, try again" | |
prompt | |
end | |
end | |
end | |
files = File.read("files.txt").lines.map(&:chomp) | |
spec_path = "spec/models/deferred_request_spec.rb" | |
puts GlobalStateSpecs.new(spec_path, seed: 39246, files: files).narrow_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment