palindrome-jagzzs 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96383db46b14cad567a660623320eb3446d8e2d9
4
+ data.tar.gz: e89276db497c8cf427cb05241ee693b9ef503d1e
5
+ SHA512:
6
+ metadata.gz: 0bed6db19adfb5dff1c90bbfc5692443cf2964c6684c7916b2c33ad3333dab1474ec641d21c42ecef7966a176a48007c5270db7e0652f13fdf152861e0a83913
7
+ data.tar.gz: 348f268325d7c07d0c602f91e3b91662ab2b8e4fd025b9d8f2212ddbd5cdc8acd0393e2d8cf74f13d9ccc9b96623bc5b377218723607db3611cb92fd89b61016
data/bin/palindrome ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/palindrome'
4
+
5
+ evaluate_input(ARGV.empty? ? nil : ARGV[0])
data/bin/palindromo ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/palindrome'
4
+
5
+ evaluate_input(ARGV.empty? ? nil : ARGV[0])
data/lib/palindrome.rb ADDED
@@ -0,0 +1,36 @@
1
+ class String
2
+ def palindrome?
3
+
4
+ if self.nil? #self can't be null, neverthless validate it
5
+ abort "Something went wrong, string input is nil"
6
+ end
7
+
8
+ text = self.scan(/[[:alnum:]]/).join.downcase #only get alphanumeric chars
9
+
10
+ if text.empty?
11
+ return false
12
+ end
13
+
14
+ is_palindrome = true
15
+ char_array = text.split ""
16
+
17
+ while char_array.length > 1 && is_palindrome
18
+ is_palindrome = char_array.pop == char_array.shift
19
+ end
20
+
21
+ is_palindrome
22
+ end
23
+ end
24
+
25
+ def evaluate_input(input)
26
+
27
+ if input.nil?
28
+ input = gets
29
+ end
30
+
31
+ if !input.palindrome?
32
+ abort "Not a palindrome"
33
+ end
34
+
35
+ exit 0
36
+ end
@@ -0,0 +1,89 @@
1
+ require_relative "palindrome"
2
+ require "test/unit"
3
+
4
+ class TestPalindrome < Test::Unit::TestCase
5
+
6
+ #negative tests
7
+ def test_empty_input_is_not_palindrome
8
+ assert_equal("".palindrome?, false, "Empty input returned that's a palindrome")
9
+ end
10
+
11
+ def test_special_chars_input_is_not_palindrome
12
+ assert_equal("!@$%^&*=".palindrome?, false, "Special chars input returned that's a palindrome")
13
+ end
14
+
15
+ def test_even_alphabetic_input_is_not_palindrome
16
+ assert_equal("abbb".palindrome?, false, "Even alphabetic input returned that's a palindrome")
17
+ end
18
+
19
+ def test_even_numeric_input_is_not_palindrome
20
+ assert_equal("1222".palindrome?, false, "Even numeric input returned that's a palindrome")
21
+ end
22
+
23
+ def test_even_alphanumeric_input_is_not_palindrome
24
+ assert_equal("a11b".palindrome?, false, "Even alphanumeric input returned that's a palindrome")
25
+ end
26
+
27
+ def test_odd_alphabetic_input_is_not_palindrome
28
+ assert_equal("ababc".palindrome?, false, "Odd alphabetic input returned that's a palindrome")
29
+ end
30
+
31
+ def test_odd_numeric_input_is_not_palindrome
32
+ assert_equal("12122".palindrome?, false, "Odd numeric input returned that's a palindrome")
33
+ end
34
+
35
+ def test_odd_alphanumeric_input_not_palindrome
36
+ assert_equal("a1a11".palindrome?, false, "Odd alphanumeric input returned that's a palindrome")
37
+ end
38
+
39
+ def test_phrase_is_not_palindrome
40
+ phrase = "This is clearly not a palindrome"
41
+ assert_equal(phrase.palindrome?, false, "The phrase \"" + phrase + "\" returned that's a palindrome")
42
+ end
43
+
44
+ def test_invalid_input_exits
45
+ assert_raise(SystemExit) { evaluate_input("This is clearly not a palindrome") }
46
+ end
47
+
48
+ #positive tests
49
+ def test_one_char_numeric_input_is_palindrome
50
+ assert_equal("1".palindrome?, true, "One char numeric input returned that's not a palindrome")
51
+ end
52
+
53
+ def test_one_char_alphabetic_input_is_palindrome
54
+ assert_equal("a".palindrome?, true, "One char alphabetic input returned that's not a palindrome")
55
+ end
56
+
57
+ def test_even_alphabetic_input_is_palindrome
58
+ assert_equal("abba".palindrome?, true, "Even alphabetic input returned that's not a palindrome")
59
+ end
60
+
61
+ def test_even_numeric_input_is_palindrome
62
+ assert_equal("1221".palindrome?, true, "Even numeric input returned that's not a palindrome")
63
+ end
64
+
65
+ def test_even_alphanumeric_input_is_palindrome
66
+ assert_equal("a11a".palindrome?, true, "Even alphanumeric input returned that's not a palindrome")
67
+ end
68
+
69
+ def test_odd_alphabetic_input_is_palindrome
70
+ assert_equal("ababa".palindrome?, true, "Odd alphabetic input returned that's not a palindrome")
71
+ end
72
+
73
+ def test_odd_numeric_input_is_palindrome
74
+ assert_equal("12121".palindrome?, true, "Odd numeric input returned that's not a palindrome")
75
+ end
76
+
77
+ def test_odd_alphanumeric_input_is_palindrome
78
+ assert_equal("a1a1a".palindrome?, true, "Odd alphanumeric input returned that's not a palindrome")
79
+ end
80
+
81
+ def test_phrase_is_palindrome
82
+ phrase = "Are we not pure? “No sir!” Panama’s moody Noriega brags. “It is garbage!” Irony dooms a man; a prisoner up to new era"
83
+ assert_equal(phrase.palindrome?, true, "The phrase \"" + phrase + "\" returned that's not a palindrome")
84
+ end
85
+
86
+ def test_valid_input_does_not_exits
87
+ assert_nothing_raised(SystemExit) { evaluate_input("abba") }
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: palindrome-jagzzs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jesus Gonzalez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple algorithm for analyzing if user's input is a palindrome.
14
+ email: jagzzs21@gmail.com
15
+ executables:
16
+ - palindrome
17
+ - palindromo
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/palindrome
22
+ - bin/palindromo
23
+ - lib/palindrome.rb
24
+ - test/tc_palindrome.rb
25
+ homepage: http://rubygems.org/gems/palindrome_jagzzs
26
+ licenses:
27
+ - Nonstandard
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - bin
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.5.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Palindrome Algorithm
50
+ test_files: []