[Matriculimit-commits] [3] trunk/test: Nesting of asserts is not working..
nobody at rubyforge.org
nobody at rubyforge.org
Sat Feb 13 02:55:36 EST 2010
Revision: 3
Author: coar
Date: 2010-02-13 02:55:35 -0500 (Sat, 13 Feb 2010)
Log Message:
-----------
Nesting of asserts is not working.. but get these into SVN
Added Paths:
-----------
trunk/test/Rakefile
trunk/test/test_data.rb
trunk/test/test_helper.rb
trunk/test/test_setof.rb
Added: trunk/test/Rakefile
===================================================================
--- trunk/test/Rakefile (rev 0)
+++ trunk/test/Rakefile 2010-02-13 07:55:35 UTC (rev 3)
@@ -0,0 +1,10 @@
+here = File.dirname(__FILE__) + '/'
+libdir = File.expand_path(here + '../lib/')
+$LOAD_PATH.unshift(libdir)
+
+task :default => [ :test_setof ]
+
+desc 'Test SetOf class'
+task :test_setof do
+ ruby "-I#{libdir} #{here}test_setof.rb"
+end
Added: trunk/test/test_data.rb
===================================================================
--- trunk/test/test_data.rb (rev 0)
+++ trunk/test/test_data.rb 2010-02-13 07:55:35 UTC (rev 3)
@@ -0,0 +1,135 @@
+require 'rubygems'
+require File.dirname(__FILE__) + '/test_helper.rb'
+require 'test/unit/assertions'
+
+module Tests
+
+ SHOULD_FAIL = false
+ SHOULD_SUCCEED = true
+
+ class TestVal
+
+ #
+ # Pattern matching classes to use this data.
+ #
+ attr_reader :to_test
+
+ #
+ # Class for the key limitation
+ #
+ attr_reader :kClass
+
+ #
+ # Class for the member limitation
+ #
+ attr_reader :mClass
+
+ #
+ # SHOULD_FAIL, SHOULD_SUCCEED, or an exception
+ #
+ attr_reader :expectation
+
+ #
+ # Actual data for the test
+ #
+ attr_reader :data
+
+ #
+ # Descriptive text (in case of failure)
+ #
+ attr_reader :desc
+
+ def initialize(settings)
+ @to_test = %r/.*/
+ @kClass = @mClass = @data = nil
+ @expectation = SHOULD_SUCCEED
+ @desc = 'Unidentified test!'
+ unless (settings.kind_of?(Hash))
+ raise ArgumentError.new('TestVal constructor argument must be a class')
+ end
+ settings.each { |k,v| eval("@#{k} = v") }
+ end # def initialize
+
+ include Test::Unit::Assertions
+
+ def test(&block)
+
+ desc = @desc
+ desc << " [expect=#{@expectation.to_s}]"
+ desc << " [mClass=#{@mClass}]"
+ desc << " [kClass=#{@kClass}]" unless (@kClass.nil?)
+ if (@expectation.ancestors.include?(Exception) rescue false)
+ assert_raise(@expectation, desc) do
+ block.call(self)
+ end
+ elsif (@expectation == SHOULD_SUCCEED)
+ assert(block.call(self), desc)
+ elsif (@expectation == SHOULD_FAIL)
+ assert(! block.call(self), desc)
+ else
+ raise RuntimeError.new('unexpected expectation: ' +
+ "#{t.expectation}:#{t.expectation.class.name}")
+ end
+ end # def test
+
+ end # class TestVal
+
+ #
+ # An array of values to use in the tests. Each element of the TestVals
+ # array is a TestVal object:
+ #
+ # TestVal.to_test Regex matching the classes which should be tested with
+ # the data (e.g., %r{^.*$} to be used in all of them).
+ # TestVal.kClass The class to which the matriculimit class' keys
+ # are to be restricted.
+ # TestVal.mClass The class to which the matriculimit class' members
+ # are to be restricted.
+ # TestVal.expectation One of SHOULD_FAIL or SHOULD_SUCCEED, indicating
+ # whether the use of the data should succeed, or
+ # the name of an exception class that should be raised.
+ # TestVal.data The actual data.
+ #
+ TestVals = [
+ TestVal.new(:to_test => %r/SetOf/,
+ :expectation => SHOULD_SUCCEED,
+ :mClass => String,
+ :data => nil,
+ :desc => 'Nil data'
+ ),
+ TestVal.new(:to_test => %r/SetOf/,
+ :expectation => SHOULD_SUCCEED,
+ :mClass => String,
+ :data => 'aString',
+ :desc => 'A simple string'
+ ),
+ TestVal.new(:to_test => %r/SetOf/,
+ :expectation => TypeError,
+ :mClass => String,
+ :data => 1,
+ :desc => 'An integer'
+ ),
+ TestVal.new(:to_test => %r/SetOf/,
+ :expectation => SHOULD_SUCCEED,
+ :mClass => String,
+ :data => %w(s1 s2 s3 s4),
+ :desc => 'An array of strings'
+ ),
+ TestVal.new(:to_test => %r/SetOf/,
+ :expectation => TypeError,
+ :mClass => String,
+ :data => (1..10).to_a,
+ :desc => 'An array of integers'
+ ),
+ TestVal.new(:to_test => %r/SetOf/,
+ :expectation => TypeError,
+ :mClass => String,
+ :data => ['a', 'b', :c, 'd'],
+ :desc => 'Array of strings ' +
+ 'but including a symbol'
+ )
+ ]
+
+ IfNoneCalled = 'IfNone invoked'
+ IfNone = lambda { return IfNoneCalled }
+
+end # module Tests
Added: trunk/test/test_helper.rb
===================================================================
--- trunk/test/test_helper.rb (rev 0)
+++ trunk/test/test_helper.rb 2010-02-13 07:55:35 UTC (rev 3)
@@ -0,0 +1,3 @@
+require 'stringio'
+require 'test/unit'
+require File.dirname(__FILE__) + '/../lib/matriculimit'
Added: trunk/test/test_setof.rb
===================================================================
--- trunk/test/test_setof.rb (rev 0)
+++ trunk/test/test_setof.rb 2010-02-13 07:55:35 UTC (rev 3)
@@ -0,0 +1,35 @@
+require 'rubygems'
+require File.dirname(__FILE__) + '/test_helper.rb'
+require File.dirname(__FILE__) + '/test_data.rb'
+
+#
+# Test the effectiveness of our class limitation on Set.
+#
+
+module Tests
+
+ class Test_SetOf < Test::Unit::TestCase
+
+ TestData = TestVals.select { |t| 'Setof'.match(t.to_test) }
+
+ #
+ # Test the various formats of constructor.
+ #
+ def test_xxx_constructor()
+ #
+ TestVals.each do |t|
+ if (t.data.nil?)
+ t.test do |t2|
+ lec = SetOf.new(t2.mClass)
+ end
+ else
+ t.test do |t2|
+ lec = SetOf.new(t2.mClass, t2.data)
+ end
+ end
+ end
+ end
+
+ end # class Test_BitStrings
+
+end # module Tests
More information about the Matriculimit-commits
mailing list