tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FeatureModel.test.js (1147B)


      1 import { FeatureModel } from "lib/InferredModel/FeatureModel.sys.mjs";
      2 
      3 const jsonData = {
      4  model_id: "test",
      5  schema_ver: 1,
      6  day_time_weighting: {
      7    days: [3, 14, 45],
      8    relative_weight: [0.33, 0.33, 0.33],
      9  },
     10  interest_vector: {
     11    cryptosport: {
     12      features: { crypto: 0.5, sport: 0.5 },
     13      thresholds: [0.3, 0.4, 0.5],
     14    },
     15    parenting: {
     16      features: { parenting: 1 },
     17      thresholds: [0.3, 0.4],
     18    },
     19  },
     20 };
     21 
     22 describe("Inferred Model", () => {
     23  it("create model", () => {
     24    const model = FeatureModel.fromJSON(jsonData);
     25    assert.equal(model.model_id, jsonData.modelId);
     26  });
     27  it("create time intervals", () => {
     28    const model = FeatureModel.fromJSON(jsonData);
     29    assert.equal(model.model_id, jsonData.modelId);
     30 
     31    const curTime = new Date();
     32    const intervals = model.getDateIntervals(curTime);
     33 
     34    assert.equal(intervals.length, jsonData.day_time_weighting.days.length);
     35    for (const interval of intervals) {
     36      assert.isTrue(interval.start < curTime.getTime());
     37      assert.isTrue(interval.end <= curTime.getTime());
     38      assert.isTrue(interval.start <= interval.end);
     39    }
     40  });
     41 });