-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrome_test.rb
81 lines (74 loc) · 2.77 KB
/
palindrome_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require "minitest/unit"
require "minitest/spec"
require "minitest/autorun"
require_relative "palindrome.rb"
class PalindromeTest < MiniTest::Unit::TestCase
describe "Palindrome" do
before do
@palindrome = Palindrome.new("")
end
describe "initialize" do
it "should throw an error if non-lowercase letters are in the string" do
#
end
end
describe "string accessor" do
it "should be able to read and write" do
@string = "test test test"
@palindrome.string = @string
assert_equal(@string, @palindrome.string )
end
end
describe "largest" do
before do
@one_palin = "lsjzlfjabababac" # abababa
@one_palin2 = "lsdflkbajkkjabdflfjbac" # bajkkjab
@two_palin = "lsdfqwertytrewqaba" #qwertytrewq
@two_same_length_palin = "lsjzlfjabababc" # ababa, babab
@no_palin = "lksjdflsjfsl" # nil
@repeat_letters = "a"*14 #itself
@repeat_letters2 = "a"*15 #itself
@more_test1 = "a"*7 + "b"*8
@more_test1b = "a"*8 + "b"*7
@more_test2 = "lsjdflsjkdfkaabjdlkjbdl" #aa
@more_test3 = "lsdfqwerytrewqaba" #aba
@more_test4 = "abalsdfqwerytrewq" #aba
@more_test5 = "ababa" #ababa
@more_test6 = "cbaabc" #ababa
@more_test7 = "cbaaabd" #ababa
end
it "should find the largest palindrome in the string" do
@palindrome.string = @one_palin
assert_equal("abababa",@palindrome.largest)
@palindrome.string = @one_palin2
assert_equal("bajkkjab",@palindrome.largest)
@palindrome.string = @two_palin
assert_equal("qwertytrewq",@palindrome.largest)
@palindrome.string = @two_same_length_palin
assert_equal("ababa",@palindrome.largest)
@palindrome.string = @no_palin
assert_equal("",@palindrome.largest)
@palindrome.string = @repeat_letters
assert_equal(@repeat_letters,@palindrome.largest)
@palindrome.string = @repeat_letters2
assert_equal(@repeat_letters2,@palindrome.largest)
@palindrome.string = @more_test1
assert_equal("b"*8,@palindrome.largest)
@palindrome.string = @more_test1b
assert_equal("a"*8,@palindrome.largest)
@palindrome.string = @more_test2
assert_equal("aa",@palindrome.largest)
@palindrome.string = @more_test3
assert_equal("aba",@palindrome.largest)
@palindrome.string = @more_test4
assert_equal("aba",@palindrome.largest)
@palindrome.string = @more_test5
assert_equal("ababa",@palindrome.largest)
@palindrome.string = @more_test6
assert_equal("cbaabc",@palindrome.largest)
@palindrome.string = @more_test7
assert_equal("baaab",@palindrome.largest)
end
end
end
end