# Copyright (c) 2010-2011 David Love # # Permission to use, copy, modify, and/or distribute this software for # any purpose with or without fee is hereby granted, provided that the # above copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # @author David Love module WhiteCloth::DataStructures require "helpers/uuid" # Check that we can create a random {UUIDTools::UUID} object. This checks # we haven't accidently broken the class definition when re-opening the # class context "Creating random UUID" do setup { UUIDTools::UUID.random_create } asserts_topic.kind_of(UUIDTools::UUID) asserts("the UUIDTools::UUID is valid") { topic.valid? } end # Create a UUID from a string. This shouldn't fail (see above), but is a # necessary pre-condition for the later checks context "Creating UUID \"984265dc-4200-4f02-ae70-fe4f48964159\"" do setup { UUIDTools::UUID.parse("984265dc-4200-4f02-ae70-fe4f48964159") } asserts_topic.kind_of(UUIDTools::UUID) asserts("the UUIDTools::UUID is valid") { topic.valid? } asserts("UUID randomly generated, hence version") { topic.version }.equals(4) asserts("UUID string") { topic.to_s }.equals("984265dc-4200-4f02-ae70-fe4f48964159") asserts("UUID hexadecimal digest") { topic.hexdigest }.equals("984265dc42004f02ae70fe4f48964159") asserts("UUID integer") { topic.to_i }.equals(202387412925962617026353010734081130841) end # Create the next UUID from the string used above. This checks the basic functionality of our # 'next' function, and that we haven't broken the UUID too much context "Creating UUID sequential to \"984265dc-4200-4f02-ae70-fe4f48964159\"" do setup { UUIDTools::UUID.parse("984265dc-4200-4f02-ae70-fe4f48964159").next } asserts_topic.kind_of(UUIDTools::UUID) asserts("the UUIDTools::UUID is valid") { topic.valid? } asserts("UUID randomly generated, hence version") { topic.version }.equals(4) asserts("UUID string") { topic.to_s }.equals("984265dc-4200-4f02-ae70-fe4f4896415a") asserts("UUID hexadecimal digest") { topic.hexdigest }.equals("984265dc42004f02ae70fe4f4896415a") asserts("UUID integer") { topic.to_i }.equals(202387412925962617026353010734081130842) end end