Changeset 224
- Timestamp:
- 06/09/05 14:15:23 (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 modified
-
lib/fm/properties (added)
-
lib/fm/properties/fuzzy.rb (added)
-
tests/property.tests.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/property.tests.rb
r210 r224 4 4 # $Id$ 5 5 # 6 # Copyright (c) 2004 The FaerieMUD Consortium. Most rights reserved.6 # Copyright (c) 2004, 2005 The FaerieMUD Consortium. Most rights reserved. 7 7 # 8 8 # This work is licensed under the Creative Commons Attribution-ShareAlike … … 30 30 class FaerieMUD::PropertiesTestCase < FaerieMUD::TestCase 31 31 32 ### An abstract property object class for testing33 class FuzzyProperty < FaerieMUD::Property34 include Comparable35 36 class << self37 attr_accessor :descriptionPair38 end39 40 def initialize( raw=0.5 )41 super()42 fVal = raw.to_f43 raise ArgumentError, "Value must be between 0 and 1, inclusive" unless44 fVal >= 0 && fVal <= 145 46 @value = fVal47 end48 49 def ==( otherProperty )50 return otherProperty.kind_of?( self.class ) &&51 otherProperty.value == @value52 end53 54 def ===( otherProperty )55 return otherProperty.kind_of?( self.class ) &&56 compare( otherProperty ) < 0.1557 end58 59 def compare( otherProperty )60 return ( otherProperty.value - @value ).abs61 end62 63 def how( specifier )64 sIndex = self.class.descriptionPair.index( specifier )65 return 0.0 unless sIndex66 67 case sIndex68 when 069 return 1.0 - @value70 71 else72 return @value73 end74 end75 76 def degree77 return @value78 end79 80 def <=>( otherProperty )81 raise ArgumentError, "Can't compare to a non-property" unless82 otherProperty.is_a?( FaerieMUD::Property )83 return @value <=> otherProperty.value84 end85 86 def occludes?( otherProp )87 raise ArgumentError, "Can't compare to a non-property" unless88 otherProp.is_a?( FaerieMUD::Property )89 self.class === otherProp90 end91 92 def to_s93 94 end95 end96 32 97 33 ### A concrete derivative of the FuzzyProperty class … … 99 35 def_kind "luster" 100 36 def_synonyms %w{brightness brilliancy shinyness} 101 Luster.descriptionPair = [ 'dull', 'shiny' ]37 def_desc_pair 'dull', 'shiny' 102 38 end 103 39 … … 182 118 183 119 ### Test the 'is' method 184 #def test_03_is185 #rval = nil120 def test_03_is 121 rval = nil 186 122 187 #tobj = @tobjClass::new188 #stobj = @stobjClass::new189 #luster = Luster::new( 0.35 )123 tobj = @tobjClass::new 124 stobj = @stobjClass::new 125 luster = Luster::new( 0.35 ) 190 126 191 #tobj.addProperties( luster )192 #assert tobj.is( "shiny" ), "test object isn't 'shiny'"193 #end127 tobj.addProperties( luster ) 128 assert tobj.is( "shiny" ), "test object isn't 'shiny'" 129 end 194 130 195 131
