1 #include "catch.hpp" 2 #include "timeline2/model/snapmodel.hpp" 3 #include <iostream> 4 #include <unordered_set> 5 6 TEST_CASE("Snap points model test", "[SnapModel]") 7 { 8 SnapModel snap; 9 10 SECTION("Basic test") 11 { 12 // empty 13 REQUIRE(snap.getClosestPoint(0) == -1); 14 REQUIRE(snap.getClosestPoint(10) == -1); 15 16 snap.addPoint(10); 17 REQUIRE(snap.getClosestPoint(0) == 10); 18 REQUIRE(snap.getClosestPoint(10) == 10); 19 REQUIRE(snap.getClosestPoint(11) == 10); 20 REQUIRE(snap.getClosestPoint(9) == 10); 21 REQUIRE(snap.getClosestPoint(999) == 10); 22 23 snap.addPoint(10); 24 REQUIRE(snap.getClosestPoint(0) == 10); 25 REQUIRE(snap.getClosestPoint(10) == 10); 26 REQUIRE(snap.getClosestPoint(11) == 10); 27 REQUIRE(snap.getClosestPoint(9) == 10); 28 REQUIRE(snap.getClosestPoint(999) == 10); 29 30 snap.addPoint(15); 31 REQUIRE(snap.getClosestPoint(0) == 10); 32 REQUIRE(snap.getClosestPoint(10) == 10); 33 REQUIRE(snap.getClosestPoint(11) == 10); 34 REQUIRE(snap.getClosestPoint(9) == 10); 35 REQUIRE(snap.getClosestPoint(12) == 10); 36 REQUIRE(snap.getClosestPoint(13) == 15); 37 REQUIRE(snap.getClosestPoint(15) == 15); 38 REQUIRE(snap.getClosestPoint(16) == 15); 39 REQUIRE(snap.getClosestPoint(999) == 15); 40 41 snap.removePoint(10); 42 REQUIRE(snap.getClosestPoint(0) == 10); 43 REQUIRE(snap.getClosestPoint(10) == 10); 44 REQUIRE(snap.getClosestPoint(11) == 10); 45 REQUIRE(snap.getClosestPoint(9) == 10); 46 REQUIRE(snap.getClosestPoint(12) == 10); 47 REQUIRE(snap.getClosestPoint(13) == 15); 48 REQUIRE(snap.getClosestPoint(15) == 15); 49 REQUIRE(snap.getClosestPoint(16) == 15); 50 REQUIRE(snap.getClosestPoint(999) == 15); 51 52 snap.removePoint(10); 53 REQUIRE(snap.getClosestPoint(0) == 15); 54 REQUIRE(snap.getClosestPoint(10) == 15); 55 REQUIRE(snap.getClosestPoint(11) == 15); 56 REQUIRE(snap.getClosestPoint(9) == 15); 57 REQUIRE(snap.getClosestPoint(12) == 15); 58 REQUIRE(snap.getClosestPoint(13) == 15); 59 REQUIRE(snap.getClosestPoint(15) == 15); 60 REQUIRE(snap.getClosestPoint(16) == 15); 61 REQUIRE(snap.getClosestPoint(999) == 15); 62 63 snap.removePoint(15); 64 REQUIRE(snap.getClosestPoint(0) == -1); 65 REQUIRE(snap.getClosestPoint(10) == -1); 66 REQUIRE(snap.getClosestPoint(11) == -1); 67 REQUIRE(snap.getClosestPoint(9) == -1); 68 REQUIRE(snap.getClosestPoint(12) == -1); 69 REQUIRE(snap.getClosestPoint(13) == -1); 70 REQUIRE(snap.getClosestPoint(15) == -1); 71 REQUIRE(snap.getClosestPoint(16) == -1); 72 REQUIRE(snap.getClosestPoint(999) == -1); 73 } 74 75 SECTION("Snappoint Ignoring") 76 { 77 REQUIRE(snap.getClosestPoint(0) == -1); 78 REQUIRE(snap.getClosestPoint(10) == -1); 79 80 snap.addPoint(10); 81 snap.addPoint(10); __anon4e7af72d0102() 82 auto state = [&]() { 83 REQUIRE(snap.getClosestPoint(0) == 10); 84 REQUIRE(snap.getClosestPoint(10) == 10); 85 REQUIRE(snap.getClosestPoint(11) == 10); 86 REQUIRE(snap.getClosestPoint(9) == 10); 87 REQUIRE(snap.getClosestPoint(999) == 10); 88 }; 89 state(); 90 91 snap.ignore({10}); 92 state(); 93 94 snap.ignore({10}); 95 REQUIRE(snap.getClosestPoint(0) == -1); 96 REQUIRE(snap.getClosestPoint(10) == -1); 97 snap.unIgnore(); 98 state(); 99 100 snap.addPoint(15); 101 REQUIRE(snap.getClosestPoint(0) == 10); 102 REQUIRE(snap.getClosestPoint(10) == 10); 103 REQUIRE(snap.getClosestPoint(11) == 10); 104 REQUIRE(snap.getClosestPoint(9) == 10); 105 REQUIRE(snap.getClosestPoint(12) == 10); 106 REQUIRE(snap.getClosestPoint(13) == 15); 107 REQUIRE(snap.getClosestPoint(15) == 15); 108 REQUIRE(snap.getClosestPoint(16) == 15); 109 REQUIRE(snap.getClosestPoint(999) == 15); 110 111 snap.ignore({15}); 112 state(); 113 snap.removePoint(10); 114 state(); 115 snap.removePoint(10); 116 REQUIRE(snap.getClosestPoint(0) == -1); 117 REQUIRE(snap.getClosestPoint(10) == -1); 118 119 snap.unIgnore(); 120 REQUIRE(snap.getClosestPoint(0) == 15); 121 REQUIRE(snap.getClosestPoint(10) == 15); 122 REQUIRE(snap.getClosestPoint(11) == 15); 123 REQUIRE(snap.getClosestPoint(9) == 15); 124 REQUIRE(snap.getClosestPoint(999) == 15); 125 } 126 } 127