<commit_before>{% extends "jstesting/base_test.html" %}
{% block testscript %}

var MS_captionManager = null;
var MS_videoPlayer = null;
var MS_editableCaptionSet = null;

/* stub caption listener machinery for testing */

var MS_dispatchedCaptions = [];
function MS_captionListener(event) {
    MS_dispatchedCaptions.push(event.caption);
}

/* a few helper methods to avoid typing too much */

function captionJSON(startTime, endTime, captionID) {
    return {'start_time' : startTime, 
	    'end_time': endTime, 
	    'caption_id': captionID};
}
function addCaptions(captions) {
    MS_captionManager.addCaptions(captions);
}
function sendEvents(playheadTime) {
    MS_videoPlayer.playheadTime = playheadTime;
    MS_videoPlayer.dispatchTimeUpdate();
}

function addNewCaption(startTime, endTime) {
    var caption = MS_editableCaptionSet.addNewCaption();
    caption.setStartTime(startTime);
    caption.setEndTime(endTime);
    return caption;
}

/* the tests */

function setUpForInitialCaptions(captions) {
    var uw = new mirosubs.UnitOfWork();
    MS_editableCaptionSet = 
	new mirosubs.subtitle.EditableCaptionSet(captions, uw);
    MS_dispatchedCaptions = [];
    MS_videoPlayer = new mirosubs.testing.StubVideoPlayer();
    MS_captionManager = new mirosubs.CaptionManager(
	MS_videoPlayer, MS_editableCaptionSet);
    MS_captionManager.addEventListener(
	mirosubs.CaptionManager.CAPTION, MS_captionListener);
}

function tearDown() {
    MS_captionManager.dispose();
    MS_videoPlayer.dispose();
    MS_editableCaptionSet.dispose();
}

function testOneCaption() {
    setUpForInitialCaptions([captionJSON(0.5, 2, 1)]);
    sendEvents(0.4);
    assertEquals(0, MS_dispatchedCaptions.length);
    sendEvents(0.6);
    assertEquals(1, MS_dispatchedCaptions.length);
    assertEquals(1, MS_dispatchedCaptions[0].getCaptionID());
}

function testTwoUpdates() {
    setUpForInitialCaptions([captionJSON(0.5, 2, 1)]);
    sendEvents(0.2);
    sendEvents(0.4);
    assertEquals(0, MS_dispatchedCaptions.length);
    sendEvents(0.6);
    sendEvents(0.8);
    assertEquals(1, MS_dispatchedCaptions.length);
}

function testRewind() {
    setUpForInitialCaptions([captionJSON(0.5, 2, 1)]);
    sendEvents(0.3);
    sendEvents(0.6);
    sendEvents(0.4);
    assertEquals(2, MS_dispatchedCaptions.length);<commit_msg>Modified unit test to catch (now corrected) problem from earlier.<commit_after>{% extends "jstesting/base_test.html" %}
{% block testscript %}

var MS_captionManager = null;
var MS_videoPlayer = null;
var MS_editableCaptionSet = null;

/* stub caption listener machinery for testing */

var MS_dispatchedCaptions = [];
function MS_captionListener(event) {
    MS_dispatchedCaptions.push(event.caption);
}

/* a few helper methods to avoid typing too much */

function captionJSON(startTime, endTime, captionID) {
    return {'start_time' : startTime, 
	    'end_time': endTime, 
	    'caption_id': captionID};
}
function addCaptions(captions) {
    MS_captionManager.addCaptions(captions);
}
function sendEvents(playheadTime) {
    MS_videoPlayer.playheadTime = playheadTime;
    MS_videoPlayer.dispatchTimeUpdate();
}

function addNewCaption(startTime, endTime) {
    var caption = MS_editableCaptionSet.addNewCaption();
    caption.setStartTime(startTime);
    caption.setEndTime(endTime);
    return caption;
}

/* the tests */

function setUpForInitialCaptions(captions) {
    var uw = new mirosubs.UnitOfWork();
    MS_editableCaptionSet = 
	new mirosubs.subtitle.EditableCaptionSet(captions, uw);
    MS_dispatchedCaptions = [];
    MS_videoPlayer = new mirosubs.testing.StubVideoPlayer();
    MS_captionManager = new mirosubs.CaptionManager(
	MS_videoPlayer, MS_editableCaptionSet);
    MS_captionManager.addEventListener(
	mirosubs.CaptionManager.CAPTION, MS_captionListener);
}

function tearDown() {
    MS_captionManager.dispose();
    MS_videoPlayer.dispose();
    MS_editableCaptionSet.dispose();
}

function testOneCaption() {
    setUpForInitialCaptions([captionJSON(0.5, 2, 1)]);
    sendEvents(0.4);
    assertEquals(0, MS_dispatchedCaptions.length);
    sendEvents(0.5);
    sendEvents(0.6);
    assertEquals(1, MS_dispatchedCaptions.length);
    assertEquals(1, MS_dispatchedCaptions[0].getCaptionID());
}

function testTwoUpdates() {
    setUpForInitialCaptions([captionJSON(0.5, 2, 1)]);
    sendEvents(0.2);
    sendEvents(0.4);
    assertEquals(0, MS_dispatchedCaptions.length);
    sendEvents(0.6);
    sendEvents(0.8);
    assertEquals(1, MS_dispatchedCaptions.length);
}

function testRewind() {
    setUpForInitialCaptions([captionJSON(0.5, 2, 1)]);
    sendEvents(0.3);
    sendEvents(0.6);
    sendEvents(0.4);
    assertEquals(2, MS_dispatchedCaptions.length);
{'fraction_non_alphanumeric': 0.11620990014871468, 'fraction_numerical': 0.016146165285744637, 'mean_word_length': 4.951959544879899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4218256', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1576, 'n_words': 265}