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

pattern matcher ruby #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions pattern_generator/lib/pattern_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'pry'
class PatternGenerator

attr_reader :letters, :numbers, :all

def initialize
@letters = ("A".."H").to_a + ("J".."N").to_a + ("P".."Z").to_a
@numbers = ("2".."9").to_a
@all = []
end

def create_all_options
first = @letters
second = @letters
third = @numbers
fourth = @letters
fifth = @numbers

first.each do |one|
second.each do |two|
third.each do |three|
fourth.each do |four|
fifth.each do |five|
@all << [one,two,three,four,five].join
end
end
end
end
end
@all.count
end

def get_a_random_one
@all = @all.shuffle
@all.pop
end


end
36 changes: 36 additions & 0 deletions pattern_generator/test/pattern_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'minitest/autorun'
require 'minitest/pride'
require './lib/pattern_generator'
require 'pry'

class PatternGeneratorTest < Minitest::Test
def test_it_exists
assert(PatternGenerator.new).is_a? PatternGenerator
end

def test_it_initalizes_with_numbers
pattern_generator = PatternGenerator.new
assert_equal ["2", "3", "4", "5", "6", "7", "8", "9"], pattern_generator.numbers
end

def test_it_initalizes_with_letters
expected = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
pattern_generator = PatternGenerator.new
assert_equal expected, pattern_generator.letters
end

def test_it_can_create_all_options
expected = 884736
pattern_generator = PatternGenerator.new
assert_equal expected, pattern_generator.create_all_options
end

def test_it_returns_a_random_one_that_will_not_be_still_avaible
pattern_generator = PatternGenerator.new
pattern_generator.create_all_options
random = pattern_generator.get_a_random_one
refute pattern_generator.all.include?(random)
end


end