Changeset 224

Show
Ignore:
Timestamp:
06/09/05 14:15:23 (3 years ago)
Author:
ged
Message:

- Worked on test coverage for properties

Location:
trunk
Files:
2 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/property.tests.rb

    r210 r224  
    44# $Id$ 
    55# 
    6 # Copyright (c) 2004 The FaerieMUD Consortium. Most rights reserved. 
     6# Copyright (c) 2004, 2005 The FaerieMUD Consortium. Most rights reserved. 
    77#  
    88# This work is licensed under the Creative Commons Attribution-ShareAlike 
     
    3030class FaerieMUD::PropertiesTestCase < FaerieMUD::TestCase 
    3131 
    32     ### An abstract property object class for testing 
    33     class FuzzyProperty < FaerieMUD::Property 
    34         include Comparable 
    35  
    36         class << self 
    37             attr_accessor :descriptionPair 
    38         end 
    39  
    40         def initialize( raw=0.5 ) 
    41             super() 
    42             fVal = raw.to_f 
    43             raise ArgumentError, "Value must be between 0 and 1, inclusive" unless 
    44                 fVal >= 0 && fVal <= 1 
    45  
    46             @value = fVal 
    47         end 
    48  
    49         def ==( otherProperty ) 
    50             return otherProperty.kind_of?( self.class ) && 
    51                 otherProperty.value == @value 
    52         end 
    53  
    54         def ===( otherProperty ) 
    55             return otherProperty.kind_of?( self.class ) && 
    56                 compare( otherProperty ) < 0.15 
    57         end 
    58  
    59         def compare( otherProperty ) 
    60             return ( otherProperty.value - @value ).abs 
    61         end 
    62  
    63         def how( specifier ) 
    64             sIndex = self.class.descriptionPair.index( specifier ) 
    65             return 0.0 unless sIndex 
    66  
    67             case sIndex 
    68             when 0 
    69                 return 1.0 - @value 
    70  
    71             else 
    72                 return @value 
    73             end 
    74         end 
    75  
    76         def degree 
    77             return @value 
    78         end 
    79  
    80         def <=>( otherProperty ) 
    81             raise ArgumentError, "Can't compare to a non-property" unless 
    82                 otherProperty.is_a?( FaerieMUD::Property ) 
    83             return @value <=> otherProperty.value 
    84         end 
    85  
    86         def occludes?( otherProp ) 
    87             raise ArgumentError, "Can't compare to a non-property" unless 
    88                 otherProp.is_a?( FaerieMUD::Property ) 
    89             self.class === otherProp 
    90         end 
    91  
    92         def to_s 
    93  
    94         end 
    95     end 
    9632 
    9733    ### A concrete derivative of the FuzzyProperty class 
     
    9935        def_kind "luster" 
    10036        def_synonyms %w{brightness brilliancy shinyness} 
    101         Luster.descriptionPair = [ 'dull', 'shiny' ] 
     37        def_desc_pair 'dull', 'shiny' 
    10238    end 
    10339 
     
    182118 
    183119    ### Test the 'is' method 
    184     #   def test_03_is 
    185     #       rval = nil 
     120    def test_03_is 
     121        rval = nil 
    186122 
    187     #       tobj = @tobjClass::new 
    188     #       stobj = @stobjClass::new 
    189     #       luster = Luster::new( 0.35 ) 
     123        tobj = @tobjClass::new 
     124        stobj = @stobjClass::new 
     125        luster = Luster::new( 0.35 ) 
    190126 
    191     #       tobj.addProperties( luster ) 
    192     #       assert tobj.is( "shiny" ), "test object isn't 'shiny'" 
    193     #   end 
     127        tobj.addProperties( luster ) 
     128        assert tobj.is( "shiny" ), "test object isn't 'shiny'" 
     129    end 
    194130 
    195131