1 // ========================================================================== 2 // Project: SproutCore - JavaScript Application Framework 3 // Copyright: ©2006-2011 Apple Inc. and contributors. 4 // License: Licensed under MIT license (see license.js) 5 // ========================================================================== 6 7 /*global module test equals context ok same notest */ 8 var set, ret ; 9 module("SC.IndexSet#without", { 10 setup: function() { 11 set = SC.IndexSet.create(1,9); 12 } 13 }); 14 15 function iter(s) { 16 var ret = []; 17 s.forEach(function(k) { ret.push(k); }); 18 return ret ; 19 } 20 21 test("should return empty set when removing self", function() { 22 ret = set.without(set); 23 ok(ret !== set, 'is not same instance'); 24 same(iter(ret), []); 25 }); 26 27 test("should return set with range removed from middle", function() { 28 ret = SC.IndexSet.create(2,6); 29 ret = set.without(ret); 30 ok(ret !== set, 'is not same instance'); 31 same(iter(ret), [1,8,9]); 32 }); 33 34 test("should return set with range removed overlapping end", function() { 35 ret = set.without(SC.IndexSet.create(6,6)); 36 ok(ret !== set, 'is not same instance'); 37 same(iter(ret), [1,2,3,4,5]); 38 }); 39 40 test("should return set with range removed overlapping beginning", function() { 41 ret = set.without(SC.IndexSet.create(0,6)); 42 ok(ret !== set, 'is not same instance'); 43 same(iter(ret), [6,7,8,9]); 44 }); 45 46 47 test("should return set with multiple ranges removed", function() { 48 ret = set.without(SC.IndexSet.create(2,2).add(6,2)); 49 ok(ret !== set, 'is not same instance'); 50 same(iter(ret), [1,4,5,8,9]); 51 }); 52 53 test("using without should properly hint returned index set", function() { 54 var set = SC.IndexSet.create(10000,5), 55 set2 = SC.IndexSet.create(10000), 56 actual = set.without(set2), 57 loc = SC.IndexSet.HINT_SIZE; 58 59 while(loc<2000) { // spot check 60 equals(actual._content[loc], 0, 'index set should have hint at loc %@ - set: %@'.fmt(loc, actual.inspect())); 61 loc += SC.IndexSet.HINT_SIZE; 62 } 63 }); 64 65 // .......................................................... 66 // NORMALIZED PARAMETER CASES 67 // 68 69 test("passing no params should return clone", function() { 70 ret = set.without(); 71 ok(ret !== set, 'is not same instance'); 72 ok(ret.isEqual(set), 'has same content'); 73 }); 74 75 test("passing single number should remove just that index", function() { 76 ret = set.without(5); 77 same(iter(ret), [1,2,3,4,6,7,8,9]); 78 }); 79 80 test("passing two numbers should remove range", function() { 81 ret = set.without(2,6); 82 same(iter(ret), [1,8,9]); 83 }); 84 85 test("passing range object should remove range", function() { 86 ret = set.without({ start: 2, length: 6 }); 87 same(iter(ret), [1,8,9]); 88 }); 89 90