anagram 0.0.1

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.
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require_relative '../lib/anagram/finder'
4
+
5
+ class TestFinder < Test::Unit::TestCase
6
+
7
+ context "signature" do
8
+ { "cat" => "act", "act" => "act", "wombat" => "abmotw" }.each do |word, signature|
9
+ should "be #{signature} for #{word}" do
10
+ assert_equal signature, Anagram::Finder.signature_of(word)
11
+ end
12
+ end
13
+ end
14
+
15
+ context "lookup" do
16
+ finder = Anagram::Finder.new(["cat", "wombat"])
17
+
18
+ should "return word if word given" do
19
+ assert_equal ["cat"], finder.lookup("cat")
20
+ end
21
+
22
+ should "return word if anagram given" do
23
+ assert_equal ["cat"], finder.lookup("act")
24
+ assert_equal ["cat"], finder.lookup("tca")
25
+ end
26
+
27
+ should "return nil if no word matches anagram" do
28
+ assert_nil finder.lookup("wibble")
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require_relative '../lib/anagram/options'
4
+
5
+ class TestOptions < Test::Unit::TestCase
6
+
7
+ context "specifying no dictionary" do
8
+ should "return default" do
9
+ opts = Anagram::Options.new(["someword"])
10
+ assert_equal Anagram::Options::DEFAULT_DICTIONARY, opts.dictionary
11
+ end
12
+ end
13
+
14
+ context "specifying a dictionary" do
15
+ should "return it" do
16
+ opts = Anagram::Options.new(["-d", "mydict", "someword"])
17
+ assert_equal "mydict", opts.dictionary
18
+ end
19
+ end
20
+
21
+ context "specifying words and no dictionary" do
22
+ should "return the words" do
23
+ opts = Anagram::Options.new(["word1", "word2"])
24
+ assert_equal ["word1", "word2"], opts.words_to_find
25
+ end
26
+ end
27
+
28
+ context "specifying words and a dictionary" do
29
+ should "return the words" do
30
+ opts = Anagram::Options.new(["-d", "mydict", "word1", "word2"])
31
+ assert_equal ["word1", "word2"], opts.words_to_find
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anagram
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Thomas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-03 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "The Anagram application searches a dictionary for anagrams of words supplied on the command line. $ anagram teaching code Anagrams of teaching: cheating, teaching Anagrams of code: code, coed It is not (currently) smart enough to deal with multi-word anagrams. This code is Copyright 2008 Dave Thomas, The Pragmatic Programmers. It is released under the terms of the MIT License. See the file LICENSE."
17
+ email: dave@pragprog.com
18
+ executables:
19
+ - anagram
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin
26
+ - bin/anagram
27
+ - lib
28
+ - lib/anagram
29
+ - lib/anagram/finder.rb
30
+ - lib/anagram/options.rb
31
+ - lib/anagram/runner.rb
32
+ - LICENSE
33
+ - Rakefile
34
+ - README
35
+ - setup.rb
36
+ - test
37
+ - test/test_finder.rb
38
+ - test/test_options.rb
39
+ has_rdoc: false
40
+ homepage: http://pragdave.pragprog.com
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "1.9"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements:
59
+ - An installed dictionary (most Unix systems have one)
60
+ rubyforge_project:
61
+ rubygems_version: 1.2.0.1824
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Find anagrams of words supplied on the command line
65
+ test_files:
66
+ - test/test_finder.rb
67
+ - test/test_options.rb