|
| 1 | +Satellite = require 'satellite' |
| 2 | + |
| 3 | +describe 'satellite', -> |
| 4 | + it "Empty tree", -> |
| 5 | + result = Satellite.tree {}, {} |
| 6 | + expected = {} |
| 7 | + assert.are.same expected, result |
| 8 | + |
| 9 | + pending "Tree with one item", -> |
| 10 | + result = Satellite.tree {"a"}, {"a"} |
| 11 | + expected = { v: "a", l: {}, r: {} } |
| 12 | + assert.are.same expected, result |
| 13 | + |
| 14 | + pending "Tree with many items", -> |
| 15 | + result = Satellite.tree {"a", "i", "x", "f", "r"}, {"i", "a", "f", "x", "r"} |
| 16 | + expected = { |
| 17 | + v: "a", |
| 18 | + l: { v: "i", l: {}, r: {} }, |
| 19 | + r: { |
| 20 | + v: "x", |
| 21 | + l: { v: "f", l: {}, r: {} }, |
| 22 | + r: { v: "r", l: {}, r: {} } |
| 23 | + } |
| 24 | + } |
| 25 | + assert.are.same expected, result |
| 26 | + |
| 27 | + pending "Reject traversals of different length", -> |
| 28 | + f = -> Satellite.tree {"a", "b"}, {"b", "a", "r"} |
| 29 | + assert.has.errors f, "traversals must have the same length" |
| 30 | + |
| 31 | + pending "Reject inconsistent traversals of same length", -> |
| 32 | + f = -> Satellite.tree {"x", "y", "z"}, {"a", "b", "c"} |
| 33 | + assert.has.errors f, "traversals must have the same elements" |
| 34 | + |
| 35 | + pending "Reject traversals with repeated items", -> |
| 36 | + f = -> Satellite.tree {"a", "b", "a"}, {"b", "a", "a"} |
| 37 | + assert.has.errors f, "traversals must contain unique items" |
| 38 | + |
| 39 | + pending "A degenerate binary tree", -> |
| 40 | + result = Satellite.tree {"a", "b", "c", "d"}, {"d", "c", "b", "a"} |
| 41 | + expected = { |
| 42 | + v: "a", |
| 43 | + l: { |
| 44 | + v: "b", |
| 45 | + l: { |
| 46 | + v: "c", |
| 47 | + l: { v: "d", l: {}, r: {} }, |
| 48 | + r: {} |
| 49 | + }, |
| 50 | + r: {} |
| 51 | + }, |
| 52 | + r: {} |
| 53 | + } |
| 54 | + assert.are.same expected, result |
| 55 | + |
| 56 | + pending "Another degenerate binary tree", -> |
| 57 | + result = Satellite.tree {"a", "b", "c", "d"}, {"a", "b", "c", "d"} |
| 58 | + expected = { |
| 59 | + v: "a", |
| 60 | + l: {}, |
| 61 | + r: { |
| 62 | + v: "b", |
| 63 | + l: {}, |
| 64 | + r: { |
| 65 | + v: "c", |
| 66 | + l: {}, |
| 67 | + r: { v: "d", l: {}, r: {} } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + assert.are.same expected, result |
| 72 | + |
| 73 | + pending "Tree with many more items", -> |
| 74 | + result = Satellite.tree {"a", "b", "d", "g", "h", "c", "e", "f", "i"}, {"g", "d", "h", "b", "a", "e", "c", "i", "f"} |
| 75 | + expected = { |
| 76 | + v: "a", |
| 77 | + l: { |
| 78 | + v: "b", |
| 79 | + l: { |
| 80 | + v: "d", |
| 81 | + l: { v: "g", l: {}, r: {} }, |
| 82 | + r: { v: "h", l: {}, r: {} } |
| 83 | + }, |
| 84 | + r: {} |
| 85 | + }, |
| 86 | + r: { |
| 87 | + v: "c", |
| 88 | + l: { v: "e", l: {}, r: {} }, |
| 89 | + r: { |
| 90 | + v: "f", |
| 91 | + l: { v: "i", l: {}, r: {} }, |
| 92 | + r: {} |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + assert.are.same expected, result |
0 commit comments