<commit_before>/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
import React, {
    AppRegistry,
    Component,
    StyleSheet,
    Text,
    View,
    ListView,
    TouchableHighlight
} from 'react-native';

const Store = require('react-native-store');
const SQLite = require('react-native-sqlite-storage');
const Realm = require('realm');

// Make SQLite module use Promises.
SQLite.enablePromise(true);

const TestObjectSchema = {
    name: "TestObject",
    properties: {
        int: "int",
        double: "double",
        date: "date",
        string: "string"
    }
}

const numTestObjects = 2000;
const numBatchTestObjects = numTestObjects * 100;
const numRepeats = 1;
const numQueryBuckets = 5;

const tests = ["insertions", "binsertions", "enumeration", "querycount", "queryenum"];
const expectedCounts = {
    insertions: numTestObjects, 
    binsertions: numBatchTestObjects, 
    enumeration: numBatchTestObjects, 
    querycount: numBatchTestObjects, 
    queryenum: numBatchTestObjects
};
const expectedResults = {
    insertions: numTestObjects, 
    binsertions: numBatchTestObjects, 
    enumeration: numBatchTestObjects, 
    querycount: numBatchTestObjects / (numQueryBuckets * 200), 
    queryenum: numBatchTestObjects / (numQueryBuckets * 200)
};

class Tests {
    async setup(testName) {
        var count = await this.count();
        if (testName == 'enumeration' || testName == 'querycount' || testName == 'queryenum') {
            if (count != expectedCounts[testName]) {
                throw "Incorrect count " + count + " for test " + testName;
            }
        }
        else {
            if (count !=  0) {
                throw "Initial count should be 0 for insertion tests";
            }
        }
    }

    async binsertions() {
        return await this.batchInsert(this.testObjects(numBatchTestObjects));
    }

    objectValues(object) {
         return Object.keys(TestObjectSchema.properties).map((prop) => object[prop])
    }

    testObjects(count) {
        var objects = [];
        for (let i = 0; i < count; i++) {
            objects.push({ int: i % numQueryBuckets, double: i, date: new Date(i), string: "" + i });
        }
        return objects;
    }
}

class RealmTests extends Tests {
    constructor() {
        super();
        this.name = 'Realm';
    }

    async setup(testName) {
        if (testName == "insertions" || testName == "binsertions") {
            Realm.clearTestState();
        }
        this.realm = new Realm({schema: [TestObjectSchema]});

        await super.setup(testName);
    }

    async insertions() {
        var realm = this.realm;
        for (var obj of this.testObjects(numTestObjects)) {
            realm.write(() => {
                realm.create("TestObject", obj);
            });
        }
        return numTestObjects;
    }

    async batchInsert(objects) {
        var realm = this.realm;
        realm.write(() => {
            for (var obj of objects) {
                realm.create("TestObject", obj);
            }
        });
        return objects.length;
    }

    async enumeration() {
        let objects = this.realm.objects('TestObject');
        let len = objects.length;
        for (let i = 0; i < len; i++) {
            var obj = objects[i];
            obj.int;
            obj.double;
            obj.date;
            obj.string;
        }
        return len;
    }

    async querycount() {
        let objects = this.realm.objects('TestObject', 'int = 0 and double < ' + numTestObjects / 2);
        return objects.length;
    }

    async queryenum() {
        let objects = this.realm.objects('TestObject', 'int = 0 and double < ' + numTestObjects / 2);
        let len = objects.length;
        for (let i = 0; i < len; i++) {
            var obj = objects[i];
            obj.int;
            obj.double;
            obj.date;
            obj.string;
        }        
        return len;
    }

    async count() {
        return this.realm.objects('TestObject').length;
    }
}

class RNStoreTests extends Tests {
    constructor() {
        super();
        this.name = "RNStore";
    }

    async setup(testName) {
        this.db = Store.model('objects');
        if (testName == "insertions" || testName == "binsertions") {
            await this.db.destroy();
        }

        await super.setup(testName);
    }

    async insertions() {
        for (var obj of this.testObjects(numTestObjects)) {
            await this.db.add(obj);
        }
        return numTestObjects;
    }

    async batchInsert(objects) {
        await this.db.multiAdd(objects);
        return objects.length;
    }

    async enumeration() {
        let objects = await this.db.find();
        let len = objects.length;
        for (let i = 0; i < len; i++) {
            var obj = objects[i];
            obj.int;
            obj.double;
            obj.date;
            obj.string;
        }<commit_msg>cast rns date to int for storage<commit_after>/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
import React, {
    AppRegistry,
    Component,
    StyleSheet,
    Text,
    View,
    ListView,
    TouchableHighlight
} from 'react-native';

const Store = require('react-native-store');
const SQLite = require('react-native-sqlite-storage');
const Realm = require('realm');

// Make SQLite module use Promises.
SQLite.enablePromise(true);

const TestObjectSchema = {
    name: "TestObject",
    properties: {
        int: "int",
        double: "double",
        date: "date",
        string: "string"
    }
}

const numTestObjects = 5000;
const numBatchTestObjects = numTestObjects * 100;
const numRepeats = 1;
const numQueryBuckets = 5;

const tests = ["insertions", "binsertions", "enumeration", "querycount", "queryenum"];
const expectedCounts = {
    insertions: numTestObjects, 
    binsertions: numBatchTestObjects, 
    enumeration: numBatchTestObjects, 
    querycount: numBatchTestObjects, 
    queryenum: numBatchTestObjects
};
const expectedResults = {
    insertions: numTestObjects, 
    binsertions: numBatchTestObjects, 
    enumeration: numBatchTestObjects, 
    querycount: numBatchTestObjects / (numQueryBuckets * 200), 
    queryenum: numBatchTestObjects / (numQueryBuckets * 200)
};

class Tests {
    async setup(testName) {
        var count = await this.count();
        if (testName == 'enumeration' || testName == 'querycount' || testName == 'queryenum') {
            if (count != expectedCounts[testName]) {
                throw "Incorrect count " + count + " for test " + testName;
            }
        }
        else {
            if (count !=  0) {
                throw "Initial count should be 0 for insertion tests";
            }
        }
    }

    async binsertions() {
        return await this.batchInsert(this.testObjects(numBatchTestObjects));
    }

    objectValues(object) {
         return Object.keys(TestObjectSchema.properties).map((prop) => object[prop])
    }

    testObjects(count) {
        var objects = [];
        for (let i = 0; i < count; i++) {
            objects.push({ int: i % numQueryBuckets, double: i, date: new Date(i), string: "" + i });
        }
        return objects;
    }
}

class RealmTests extends Tests {
    constructor() {
        super();
        this.name = 'Realm';
    }

    async setup(testName) {
        if (testName == "insertions" || testName == "binsertions") {
            Realm.clearTestState();
        }
        this.realm = new Realm({schema: [TestObjectSchema]});

        await super.setup(testName);
    }

    async insertions() {
        var realm = this.realm;
        for (var obj of this.testObjects(numTestObjects)) {
            realm.write(() => {
                realm.create("TestObject", obj);
            });
        }
        return numTestObjects;
    }

    async batchInsert(objects) {
        var realm = this.realm;
        realm.write(() => {
            for (var obj of objects) {
                realm.create("TestObject", obj);
            }
        });
        return objects.length;
    }

    async enumeration() {
        let objects = this.realm.objects('TestObject');
        let len = objects.length;
        for (let i = 0; i < len; i++) {
            var obj = objects[i];
            obj.int;
            obj.double;
            obj.date;
            obj.string;
        }
        return len;
    }

    async querycount() {
        let objects = this.realm.objects('TestObject', 'int = 0 and double < ' + numTestObjects / 2);
        return objects.length;
    }

    async queryenum() {
        let objects = this.realm.objects('TestObject', 'int = 0 and double < ' + numTestObjects / 2);
        let len = objects.length;
        for (let i = 0; i < len; i++) {
            var obj = objects[i];
            obj.int;
            obj.double;
            obj.date;
            obj.string;
        }        
        return len;
    }

    async count() {
        return this.realm.objects('TestObject').length;
    }
}

class RNStoreTests extends Tests {
    constructor() {
        super();
        this.name = "RNStore";
    }

    async setup(testName) {
        this.db = Store.model('objects');
        if (testName == "insertions" || testName == "binsertions") {
            await this.db.destroy();
        }

        await super.setup(testName);
    }

    async insertions() {
        for (var obj of this.testObjects(numTestObjects)) {
            obj.date = obj.date.getTime();
            await this.db.add(obj);
        }
        return numTestObjects;
    }

    async batchInsert(objects) {
        await this.db.multiAdd(objects);
        for (var obj of this.testObjects(numTestObjects)) {
            obj.date = obj.date.getTime();
        }
        return objects.length;
    }

    async enumeration() {
        let objects = await this.db.find();
        let len = objects.length;
        for (let i = 0; i < len; i++) {
            var obj = objects[i];
            obj.int;
            obj.double;
            new Date(obj.date);
            obj.string;
        }
{'fraction_non_alphanumeric': 0.12281740159810595, 'fraction_numerical': 0.0049324257669922066, 'mean_word_length': 1.9402552204176333, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2391824', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2907, 'n_words': 714}