module("MDLInterpreter");

test("Check Write Empty Molecule", function(){
    var out = writeMOL(new Molecule());
    expect(1);
    ok(out != null && out.length > 0, 'Check output isn\'t empty');
});

test("Check Read Without Error", function(){
    var mol = readMOL(thiophene);
    expect(2);
    equals(5, mol.atoms.length, 'Check 5 atoms');
    equals(5, mol.bonds.length, 'Check 5 bonds');
});

test("Check Write Without Error", function(){
    var mol = new Molecule();
    mol.atoms[0] = new Atom();
    mol.atoms[1] = new Atom();
    mol.bonds[0] = new Bond(mol.atoms[0], mol.atoms[1]);
    var out = writeMOL(mol);
    expect(1);
    ok(out != null && out.length > 0, 'Check output isn\'t empty');
});

test("Check Reversible", function(){
    var mol = readMOL(writeMOL(readMOL(thiophene)));
    expect(2);
    equals(5, mol.atoms.length, 'Check 5 atoms');
    equals(5, mol.bonds.length, 'Check 5 bonds');
});

test("Check Bond Orders", function(){
    var mol = readMOL(writeMOL(readMOL(testBondOrders)));
    var booleans = [false, false, false, false, false, false];
    for (var i = 0; i < mol.bonds.length; i++) {
        if (mol.bonds[i].bondOrder == 1 && mol.bonds[i].stereo == BOND_STEREO_NONE) {
            booleans[0] = true;
        }
        else 
            if (mol.bonds[i].bondOrder == 1 && mol.bonds[i].stereo == BOND_STEREO_PROTRUDING) {
                booleans[1] = true;
            }
            else 
                if (mol.bonds[i].bondOrder == 1 && mol.bonds[i].stereo == BOND_STEREO_RECESSED) {
                    booleans[2] = true;
                }
                else 
                    if (mol.bonds[i].bondOrder == 2 && mol.bonds[i].stereo == BOND_STEREO_NONE) {
                        booleans[3] = true;
                    }
                    else 
                        if (mol.bonds[i].bondOrder == 2 && mol.bonds[i].stereo == BOND_STEREO_AMBIGUOUS) {
                            booleans[4] = true;
                        }
                        else 
                            if (mol.bonds[i].bondOrder == 3 && mol.bonds[i].stereo == BOND_STEREO_NONE) {
                                booleans[5] = true;
                            }
    }
    for (var i = 0; i < booleans.length; i++) {
        ok(booleans[i], 'Check Bond was Present');
    }
});

test("Check Charges Read", function(){
    var mol1 = readMOL(thiophene);
    var mol2 = readMOL(chargeTest);
    expect(9);
    for (var i = 0; i < mol1.atoms.length; i++) {
        equals(0, mol1.atoms[i].charge, 'Charges should all be 0 for thiophene');
    }
    equals(-1, mol2.atoms[0].charge, 'Check Charge 1');
    equals(2, mol2.atoms[1].charge, 'Check Charge 2');
    equals(-3, mol2.atoms[2].charge, 'Check Charge 3');
    equals(0, mol2.atoms[3].charge, 'Check Charge 4');
});

test("Check Charges Written", function(){
    var mol1 = readMOL(writeMOL(readMOL(thiophene)));
    var mol2 = readMOL(writeMOL(readMOL(chargeTest)));
    expect(9);
    for (var i = 0; i < mol1.atoms.length; i++) {
        equals(0, mol1.atoms[i].charge, 'Charges should all be 0 for thiophene');
    }
    equals(-1, mol2.atoms[0].charge, 'Check Charge 1');
    equals(2, mol2.atoms[1].charge, 'Check Charge 2');
    equals(-3, mol2.atoms[2].charge, 'Check Charge 3');
    equals(0, mol2.atoms[3].charge, 'Check Charge 4');
});
