public void TestStartFinishRecording()
    {
        ButtonPressingMetric bpm = new ButtonPressingMetric();

        Assert.IsFalse(bpm.isRecording);    // isRecording start out false

        bpm.startRecording();
        Assert.IsTrue(bpm.isRecording);     // Should be true now

        bpm.finishRecording();
        Assert.IsFalse(bpm.isRecording);    // Should be false now

        bpm.startRecording();
        Assert.IsTrue(bpm.isRecording);
        bpm.startRecording();
        Assert.IsTrue(bpm.isRecording);     // Redundant calls to startRecording still keep it true

        bpm.finishRecording();
        Assert.IsFalse(bpm.isRecording);
        bpm.finishRecording();
        Assert.IsFalse(bpm.isRecording);    // Redundant calls to finishRecording still keep is false
    }
Пример #2
0
    // End game, finish recording metrics
    public void EndGame()
    {
        bpMetric.finishRecording();
        var str = metricWriter.GetLogMetrics(
            DateTime.Now,
            new List <AbstractMetric>()
        {
            bpMetric
        }
            );

        StartCoroutine(Post("digger_" + DateTime.Now.ToFileTime() + ".json", str));
        EndLevel(4f);
    }
    public void TestGetJSON()
    {
        // Test getJSON() when metric has no records
        ButtonPressingMetric bpm1 = new ButtonPressingMetric();

        Assert.IsEmpty(bpm1.eventList);

        JObject json1 = bpm1.getJSON();

        Assert.IsNotNull(json1);
        Assert.IsNotNull(json1["metricName"]);      // JSON entry "buttonPressing" should be empty, as nothing has been recorded
        Assert.IsEmpty(json1["eventList"]);

        // Test getJSON() with one record
        ButtonPressingMetric bpm2 = new ButtonPressingMetric();

        bpm2.startRecording();
        Assert.IsTrue(bpm2.isRecording);
        Assert.IsEmpty(bpm2.eventList);

        bpm2.recordEvent(new ButtonPressingEvent(new System.DateTime(2021, 2, 1), KeyCode.B, true));
        bpm2.finishRecording();

        JObject json2 = bpm2.getJSON();

        Assert.IsNotNull(json2);
        Assert.IsNotNull(json2["metricName"]);

        JArray eventList2 = (JArray)json2["eventList"];

        Assert.AreEqual("buttonPressing", json2["metricName"].ToString());
        Assert.AreEqual(1, eventList2.Count);
        Assert.AreEqual("2021-02-01 12:00:00 AM", eventList2[0]["eventTime"].ToString());
        Assert.AreEqual(KeyCode.B, eventList2[0]["keyCode"].ToObject <KeyCode>());
        Assert.AreEqual(true, eventList2[0]["keyDown"].ToObject <bool>());

        // Test getJSON() with multiple records
        ButtonPressingMetric bpm3 = new ButtonPressingMetric();

        bpm3.startRecording();
        Assert.IsTrue(bpm3.isRecording);
        Assert.IsEmpty(bpm3.eventList);

        bpm3.recordEvent(new ButtonPressingEvent(new System.DateTime(2021, 2, 7, 13, 12, 15), KeyCode.A, true));
        bpm3.recordEvent(new ButtonPressingEvent(new System.DateTime(2021, 2, 7, 13, 12, 16), KeyCode.A, false));
        bpm3.recordEvent(new ButtonPressingEvent(new System.DateTime(2022, 4, 1), KeyCode.LeftAlt, true));
        bpm3.finishRecording();
        bpm3.recordEvent(new ButtonPressingEvent(new System.DateTime(2023, 1, 3), KeyCode.M, false));    // record an event after finishing recording
        Assert.IsFalse(bpm3.isRecording);

        JObject json3 = bpm3.getJSON();

        Assert.IsNotNull(json3);
        Assert.IsNotNull(json3["metricName"]);

        JArray eventList3 = (JArray)json3["eventList"];

        Assert.AreEqual(3, eventList3.Count);

        Assert.AreEqual("2021-02-07 1:12:15 PM", eventList3[0]["eventTime"].ToString());
        Assert.AreEqual(KeyCode.A, eventList3[0]["keyCode"].ToObject <KeyCode>());
        Assert.AreEqual(true, eventList3[0]["keyDown"].ToObject <bool>());

        Assert.AreEqual("2021-02-07 1:12:16 PM", eventList3[1]["eventTime"].ToString());
        Assert.AreEqual(KeyCode.A, eventList3[1]["keyCode"].ToObject <KeyCode>());
        Assert.AreEqual(false, eventList3[1]["keyDown"].ToObject <bool>());

        Assert.AreEqual("2022-04-01 12:00:00 AM", eventList3[2]["eventTime"].ToString());
        Assert.AreEqual(KeyCode.LeftAlt, eventList3[2]["keyCode"].ToObject <KeyCode>());
        Assert.AreEqual(true, eventList3[2]["keyDown"].ToObject <bool>());
    }