WhiteCloth 0.0.2 → 0.0.4
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.
- data/Gemfile +4 -0
- data/Gemfile.lock +4 -0
- data/HISTORY +25 -4
- data/Rakefile +5 -1
- data/VERSION +1 -1
- data/{FluxTuna.gemspec → WhiteCloth.gemspec} +25 -6
- data/lib/data_structures.rb +25 -0
- data/lib/data_structures/standard_node.rb +64 -0
- data/lib/data_structures/standard_tree.rb +99 -0
- data/lib/data_structures/white_node.rb +201 -0
- data/lib/helpers/tree_builder.rb +43 -0
- data/{test/dir_walk/create_witness_test.rb → lib/helpers/uuid.rb} +14 -18
- data/lib/projections.rb +28 -0
- data/lib/projections/project_dir.rb +51 -0
- data/lib/projections/project_file.rb +0 -0
- data/test/data/data_test.rb +1 -1
- data/test/data_structures/basic_tree_test.rb +122 -0
- data/test/data_structures/standard_tree_test.rb +118 -0
- data/test/data_structures/uuid_test.rb +56 -0
- data/test/projections/project_file_test.rb +77 -0
- metadata +68 -34
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright (c) 2010-2011 David Love
|
2
|
+
#
|
3
|
+
# Permission to use, copy, modify, and/or distribute this software for
|
4
|
+
# any purpose with or without fee is hereby granted, provided that the
|
5
|
+
# above copyright notice and this permission notice appear in all copies.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
+
#
|
15
|
+
|
16
|
+
# @author David Love
|
17
|
+
|
18
|
+
module WhiteCloth::DataStructures
|
19
|
+
|
20
|
+
# Load the UUID class, as extended by the helper library
|
21
|
+
require "helpers/uuid"
|
22
|
+
|
23
|
+
# Helper class for constructing trees. Takes care of the basic manipulation of the trees, allowing
|
24
|
+
# some abstraction in the projections.
|
25
|
+
class TreeBuilder
|
26
|
+
|
27
|
+
# Default constructor. Creates an internal UUID, which is used to sequence objects
|
28
|
+
# added to the {TreeBuilder}.
|
29
|
+
def initialize
|
30
|
+
|
31
|
+
# Call the parent to create the underlying stack
|
32
|
+
super()
|
33
|
+
|
34
|
+
# Create our sequence number
|
35
|
+
@sequence = UUIDTools::UUID.random_create
|
36
|
+
|
37
|
+
# Create the level stack
|
38
|
+
@level_stack = Containers::Stack.new
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -15,25 +15,21 @@
|
|
15
15
|
|
16
16
|
# @author David Love
|
17
17
|
|
18
|
-
|
19
|
-
# This test suite checks we can create the relevant witness objects
|
20
|
-
#
|
21
|
-
module Test::Witness
|
22
|
-
|
23
|
-
# Include the standard witness classes
|
24
|
-
include FluxTuna::Witness
|
18
|
+
require "uuidtools"
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
asserts_topic.kind_of(FluxTuna::Witness::DirFileWitness)
|
30
|
-
end
|
20
|
+
# Extendes the {UUIDTools::UUID} class, adding the ability to
|
21
|
+
# generate sequential UUID's
|
22
|
+
class UUIDTools::UUID
|
31
23
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
# Increments the internal UUID representation, returning a
|
25
|
+
# new UUID that is different from, but greater, than the
|
26
|
+
# current sequence number
|
27
|
+
def next
|
28
|
+
next_uuid = self.to_i
|
29
|
+
next_uuid += 1
|
30
|
+
|
31
|
+
# Return the newly created UUID
|
32
|
+
return UUIDTools::UUID::parse_int(next_uuid)
|
36
33
|
end
|
37
|
-
|
34
|
+
|
38
35
|
end
|
39
|
-
|
data/lib/projections.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2011 David Love
|
2
|
+
#
|
3
|
+
# Permission to use, copy, modify, and/or distribute this software for
|
4
|
+
# any purpose with or without fee is hereby granted, provided that the
|
5
|
+
# above copyright notice and this permission notice appear in all copies.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
+
#
|
15
|
+
|
16
|
+
# @author David Love
|
17
|
+
|
18
|
+
# Loads all the standards projections
|
19
|
+
module WhiteCloth::Projections
|
20
|
+
|
21
|
+
# Load the additional data structures required by the projections
|
22
|
+
require "data_structures"
|
23
|
+
include WhiteCloth::DataStructures
|
24
|
+
|
25
|
+
# Load the known projections
|
26
|
+
require "projections/project_dir.rb"
|
27
|
+
require "projections/project_file.rb"
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2010-2011 David Love
|
2
|
+
#
|
3
|
+
# Permission to use, copy, modify, and/or distribute this software for
|
4
|
+
# any purpose with or without fee is hereby granted, provided that the
|
5
|
+
# above copyright notice and this permission notice appear in all copies.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
+
#
|
15
|
+
|
16
|
+
# @author David Love
|
17
|
+
|
18
|
+
module WhiteCloth::Projections
|
19
|
+
|
20
|
+
# Create a Projection for the specified directory
|
21
|
+
class DirFile
|
22
|
+
|
23
|
+
# Default constructor
|
24
|
+
def initialize
|
25
|
+
@file_stack = WhiteCloth::DataStructures::FlatTree.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# Run the projection function, taking +path+ as the {File#glob}
|
29
|
+
# shell glob for the path and pattern to match
|
30
|
+
# when looking for files
|
31
|
+
def project(path)
|
32
|
+
|
33
|
+
# Walk the path,
|
34
|
+
Dir.glob(path){|file_name|
|
35
|
+
|
36
|
+
# Ignore directories
|
37
|
+
unless File.directory?(file_name) then
|
38
|
+
|
39
|
+
# Ignore the special files as well
|
40
|
+
unless file_name == "." or file_name == ".." then
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
File without changes
|
data/test/data/data_test.rb
CHANGED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Copyright (c) 2011 David Love
|
2
|
+
#
|
3
|
+
# Based on the file testtree.rb, part of the RubyTree package.
|
4
|
+
# Copyright (c) 2006, 2007, 2008, 2009, 2010 Anupam Sengupta.
|
5
|
+
#
|
6
|
+
# Modified for use with the Riot test framework, and integration into the other
|
7
|
+
# tests
|
8
|
+
#
|
9
|
+
# All rights reserved.
|
10
|
+
#
|
11
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
12
|
+
# are permitted provided that the following conditions are met:
|
13
|
+
#
|
14
|
+
# - Redistributions of source code must retain the above copyright notice, this
|
15
|
+
# list of conditions and the following disclaimer.
|
16
|
+
#
|
17
|
+
# - Redistributions in binary form must reproduce the above copyright notice, this
|
18
|
+
# list of conditions and the following disclaimer in the documentation and/or
|
19
|
+
# other materials provided with the distribution.
|
20
|
+
#
|
21
|
+
# - Neither the name of the organization nor the names of its contributors may
|
22
|
+
# be used to endorse or promote products derived from this software without
|
23
|
+
# specific prior written permission.
|
24
|
+
#
|
25
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
27
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
29
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
30
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
31
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
32
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
33
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
34
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
#
|
36
|
+
|
37
|
+
require 'tree'
|
38
|
+
|
39
|
+
module Test::DataStructures
|
40
|
+
|
41
|
+
# Create this structure for the tests
|
42
|
+
#
|
43
|
+
# +----------+
|
44
|
+
# | ROOT |
|
45
|
+
# +-+--------+
|
46
|
+
# |
|
47
|
+
# | +---------------+
|
48
|
+
# +----+ CHILD1 |
|
49
|
+
# | +---------------+
|
50
|
+
# |
|
51
|
+
# | +---------------+
|
52
|
+
# +----+ CHILD2 |
|
53
|
+
# | +---------------+
|
54
|
+
# |
|
55
|
+
# | +---------------+ +------------------+
|
56
|
+
# +----+ CHILD3 +---+ CHILD4 |
|
57
|
+
# +---------------+ +------------------+
|
58
|
+
#
|
59
|
+
|
60
|
+
# This test is for the root alone - without any children being linked
|
61
|
+
context "Sanity tests for the Basic Tree root node" do
|
62
|
+
setup {
|
63
|
+
root = Tree::TreeNode.new("ROOT", "Root Node")
|
64
|
+
}
|
65
|
+
|
66
|
+
denies("root node"){ topic }.nil
|
67
|
+
asserts("parent of root node") { topic.parent }.nil
|
68
|
+
denies("root name") { topic.name }.nil
|
69
|
+
asserts("root name") { topic.name }.equals("ROOT")
|
70
|
+
asserts("root contents") { topic.content }.equals("Root Node")
|
71
|
+
asserts("root node declares as the root node") { topic.is_root? }
|
72
|
+
denies("root cannot have any children") { topic.has_children? }
|
73
|
+
asserts("root has contents") { topic.has_content? }
|
74
|
+
asserts("number of nodes should be one") { topic.size }.equals(1)
|
75
|
+
asserts("root does not have any children") { topic.siblings.nil? }
|
76
|
+
asserts("root should have an in-degree that") { topic.in_degree }.equals(0)
|
77
|
+
asserts("root's height before adding any children") { topic.node_height }.equals(0)
|
78
|
+
end
|
79
|
+
|
80
|
+
context "Sanity tests for the Basic Tree after the children are linked to the root" do
|
81
|
+
setup {
|
82
|
+
@root = Tree::TreeNode.new("ROOT", "Root Node")
|
83
|
+
|
84
|
+
@child1 = Tree::TreeNode.new("Child1", "Child Node 1")
|
85
|
+
@child2 = Tree::TreeNode.new("Child2", "Child Node 2")
|
86
|
+
@child3 = Tree::TreeNode.new("Child3", "Child Node 3")
|
87
|
+
@child4 = Tree::TreeNode.new("Child4", "Grand Child 1")
|
88
|
+
@child5 = Tree::TreeNode.new("Child5", "Child Node 4")
|
89
|
+
|
90
|
+
@root << @child1
|
91
|
+
@root << @child2
|
92
|
+
@root << @child3 << @child4
|
93
|
+
|
94
|
+
@root
|
95
|
+
}
|
96
|
+
|
97
|
+
asserts("root's root is self") { topic.root == topic }
|
98
|
+
asserts("child 1's root should be ROOT") { @child1.root == topic }
|
99
|
+
asserts("child 4's root should be ROOT") { @child4.root == topic }
|
100
|
+
asserts("root's height after adding the children") { topic.node_height }.equals(2)
|
101
|
+
end
|
102
|
+
|
103
|
+
context "Test the new nodes have no content" do
|
104
|
+
setup { a_node = Tree::TreeNode.new("A Node") }
|
105
|
+
|
106
|
+
asserts("the node should not have content") { topic.content }.nil
|
107
|
+
denies("the node should not have content") { topic.has_content? }
|
108
|
+
end
|
109
|
+
|
110
|
+
context "Test the presence of content in the nodes" do
|
111
|
+
setup {
|
112
|
+
a_node = Tree::TreeNode.new("A Node")
|
113
|
+
a_node.content = "Something"
|
114
|
+
|
115
|
+
a_node
|
116
|
+
}
|
117
|
+
|
118
|
+
denies("the node should now have content") { topic.content }.nil
|
119
|
+
asserts("the node should now have content") { topic.has_content? }
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# Copyright (c) 2010-2011 David Love
|
2
|
+
#
|
3
|
+
# Permission to use, copy, modify, and/or distribute this software for
|
4
|
+
# any purpose with or without fee is hereby granted, provided that the
|
5
|
+
# above copyright notice and this permission notice appear in all copies.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
+
#
|
15
|
+
|
16
|
+
# @author David Love
|
17
|
+
|
18
|
+
#
|
19
|
+
# This test suite checks for the correct behaviour of the {FlatTree} data
|
20
|
+
# structure
|
21
|
+
#
|
22
|
+
module Test::DataStructures
|
23
|
+
|
24
|
+
require "data_structures"
|
25
|
+
include WhiteCloth::DataStructures
|
26
|
+
|
27
|
+
# Check that we can create a {StandardTree}
|
28
|
+
context "Creating empty Standard Tree" do
|
29
|
+
setup { StandardTree.new }
|
30
|
+
asserts_topic.kind_of(WhiteCloth::DataStructures::StandardTree)
|
31
|
+
asserts("the Standard Tree is empty") { topic.empty? }
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create this structure for the tests
|
35
|
+
#
|
36
|
+
# +----------+
|
37
|
+
# | ROOT |
|
38
|
+
# +-+--------+
|
39
|
+
# |
|
40
|
+
# | +---------------+
|
41
|
+
# +----+ Child 1 |
|
42
|
+
# | +---------------+
|
43
|
+
# |
|
44
|
+
# | +---------------+
|
45
|
+
# +----+ Child 2 |
|
46
|
+
# | +---------------+
|
47
|
+
# |
|
48
|
+
# | +---------------+ +------------------+ +---------------------+
|
49
|
+
# +----+ Child 3 +---+ Grand Child 1 +---+ Great Grand Child 1 |
|
50
|
+
# | +---------------+ +------------------+ +---------------------+
|
51
|
+
# |
|
52
|
+
# | +---------------+ +------------------+
|
53
|
+
# +----+ Child 4 +---+ Grand Child 2 |
|
54
|
+
# +---------------+ +------------------+
|
55
|
+
#
|
56
|
+
|
57
|
+
# This test is for the root alone - without any children being linked
|
58
|
+
context "Check the Standard Tree root node behaves as it should" do
|
59
|
+
setup {
|
60
|
+
@root = StandardTree.new("b081eabd-8799-4885-8c4d-eb3cf76b30b4")
|
61
|
+
}
|
62
|
+
|
63
|
+
denies("root node"){ topic }.nil
|
64
|
+
asserts("parent of root node") { topic[nil].parent }.nil
|
65
|
+
denies("root name") { topic[nil].id }.nil
|
66
|
+
asserts("root name") { topic[nil].id }.equals("b081eabd-8799-4885-8c4d-eb3cf76b30b4")
|
67
|
+
asserts("root contents") { topic[nil].content }.nil
|
68
|
+
asserts("root node declares as the root node") { topic[nil].is_root? }
|
69
|
+
denies("root cannot have any children") { topic[nil].has_children? }
|
70
|
+
denies("root has contents") { topic[nil].has_content? }
|
71
|
+
asserts("number of nodes should be one") { topic[nil].size }.equals(1)
|
72
|
+
asserts("root does not have any children") { topic[nil].siblings.nil? }
|
73
|
+
asserts("root should have an in-degree that") { topic[nil].in_degree }.equals(0)
|
74
|
+
asserts("root's height before adding any children") { topic[nil].node_height }.equals(0)
|
75
|
+
end
|
76
|
+
|
77
|
+
context "Check that the Standard Tree adds new nodes correctly" do
|
78
|
+
setup {
|
79
|
+
@root = StandardTree.new("b081eabd-8799-4885-8c4d-eb3cf76b30b4")
|
80
|
+
|
81
|
+
@root << {nil => "Child 1"}
|
82
|
+
@root << {nil => "Child 2", nil => "Child 3"}
|
83
|
+
@root << {nil => "Child 3", "Child Node 3" => "Grand Child 1"}
|
84
|
+
@root << {nil => "Child 4"}
|
85
|
+
@root << {"Child 4" => "Grand Child 2", "Grand Child 1" => "Great Grand Child 1"}
|
86
|
+
|
87
|
+
@root
|
88
|
+
}
|
89
|
+
|
90
|
+
asserts("root's root is self") { topic[nil].root == topic[nil] }
|
91
|
+
asserts("child 1's root should be ROOT") { topic["Child 1"].root == topic[nil] }
|
92
|
+
asserts("child 4's root should be ROOT") { topic["Child 4"].root == topic[nil] }
|
93
|
+
asserts("great grand child 1's parent should be \"Grand Child 1\"") { topic["Great Grand Child 1"].parent == topic["Grand Child 1"] }
|
94
|
+
denies("great grand child 1's parent should be \"Child 3\"") { topic["Great Grand Child 1"].parent == topic["Child 3"] }
|
95
|
+
asserts("root's height after adding the children") { topic[nil].node_height }.equals(2)
|
96
|
+
end
|
97
|
+
|
98
|
+
context "Test the new nodes have no content" do
|
99
|
+
setup { a_node = Tree::TreeNode.new("A Node") }
|
100
|
+
|
101
|
+
asserts("the node should not have content") { topic.content }.nil
|
102
|
+
denies("the node should not have content") { topic.has_content? }
|
103
|
+
end
|
104
|
+
|
105
|
+
context "Test the presence of content in the nodes" do
|
106
|
+
setup {
|
107
|
+
a_node = Tree::TreeNode.new("A Node")
|
108
|
+
a_node.content = "Something"
|
109
|
+
|
110
|
+
a_node
|
111
|
+
}
|
112
|
+
|
113
|
+
denies("the node should now have content") { topic.content }.nil
|
114
|
+
asserts("the node should now have content") { topic.has_content? }
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright (c) 2010-2011 David Love
|
2
|
+
#
|
3
|
+
# Permission to use, copy, modify, and/or distribute this software for
|
4
|
+
# any purpose with or without fee is hereby granted, provided that the
|
5
|
+
# above copyright notice and this permission notice appear in all copies.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
+
#
|
15
|
+
|
16
|
+
# @author David Love
|
17
|
+
|
18
|
+
module WhiteCloth::DataStructures
|
19
|
+
|
20
|
+
require "helpers/uuid"
|
21
|
+
|
22
|
+
# Check that we can create a random {UUIDTools::UUID} object. This checks
|
23
|
+
# we haven't accidently broken the class definition when re-opening the
|
24
|
+
# class
|
25
|
+
context "Creating random UUID" do
|
26
|
+
setup { UUIDTools::UUID.random_create }
|
27
|
+
asserts_topic.kind_of(UUIDTools::UUID)
|
28
|
+
asserts("the UUIDTools::UUID is valid") { topic.valid? }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create a UUID from a string. This shouldn't fail (see above), but is a
|
32
|
+
# necessary pre-condition for the later checks
|
33
|
+
context "Creating UUID \"984265dc-4200-4f02-ae70-fe4f48964159\"" do
|
34
|
+
setup { UUIDTools::UUID.parse("984265dc-4200-4f02-ae70-fe4f48964159") }
|
35
|
+
asserts_topic.kind_of(UUIDTools::UUID)
|
36
|
+
asserts("the UUIDTools::UUID is valid") { topic.valid? }
|
37
|
+
asserts("UUID randomly generated, hence version") { topic.version }.equals(4)
|
38
|
+
asserts("UUID string") { topic.to_s }.equals("984265dc-4200-4f02-ae70-fe4f48964159")
|
39
|
+
asserts("UUID hexadecimal digest") { topic.hexdigest }.equals("984265dc42004f02ae70fe4f48964159")
|
40
|
+
asserts("UUID integer") { topic.to_i }.equals(202387412925962617026353010734081130841)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create the next UUID from the string used above. This checks the basic functionality of our
|
44
|
+
# 'next' function, and that we haven't broken the UUID too much
|
45
|
+
context "Creating UUID sequential to \"984265dc-4200-4f02-ae70-fe4f48964159\"" do
|
46
|
+
setup { UUIDTools::UUID.parse("984265dc-4200-4f02-ae70-fe4f48964159").next }
|
47
|
+
asserts_topic.kind_of(UUIDTools::UUID)
|
48
|
+
asserts("the UUIDTools::UUID is valid") { topic.valid? }
|
49
|
+
asserts("UUID randomly generated, hence version") { topic.version }.equals(4)
|
50
|
+
asserts("UUID string") { topic.to_s }.equals("984265dc-4200-4f02-ae70-fe4f4896415a")
|
51
|
+
asserts("UUID hexadecimal digest") { topic.hexdigest }.equals("984265dc42004f02ae70fe4f4896415a")
|
52
|
+
asserts("UUID integer") { topic.to_i }.equals(202387412925962617026353010734081130842)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|