1 // ==========================================================================
  2 // Project:   SproutCore Costello - Property Observing Library
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            Portions ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 
  8 /*globals module test ok isObj equals expects */
  9 
 10 var Rectangle = SC.Object.extend({
 11   length: 0,
 12   width: 0,
 13   
 14   area: function() {
 15     return this.get('length') * this.get('width');
 16   }
 17 });
 18 
 19 Rectangle.mixin(SC.Comparable, {
 20   compare: function(a, b) {
 21     return SC.compare(a.area(), b.area());
 22   }
 23 });
 24 
 25 var r1, r2;
 26 
 27 module("Comparable", {
 28   
 29   setup: function() {
 30     r1 = Rectangle.create({length: 6, width: 12});
 31     r2 = Rectangle.create({length: 6, width: 13});
 32   },
 33   
 34   teardown: function() {
 35   }
 36   
 37 });
 38 
 39 test("should be comparable and return the correct result", function() {
 40   equals(r1.constructor.isComparable, YES);
 41   equals(SC.compare(r1, r1), 0);
 42   equals(SC.compare(r1, r2), -1);
 43   equals(SC.compare(r2, r1), 1);
 44 });
 45