module("Atom");

test("Check Creation", function(){
	var empty = new Atom();
	var justLabel = new Atom('N');
	var justLabelXY = new Atom('N', 10, 10);
	var entire = new Atom('N', 10, 10, 10);
	expect(16);
    equals('C', empty.label, 'Check empty label');
	equals(0, empty.x, 'Check empty x');
	equals(0, empty.y, 'Check empty y');
	equals(0, empty.z, 'Check empty z');
    equals('N', justLabel.label, 'Check justLabel label');
	equals(0, justLabel.x, 'Check justLabel x');
	equals(0, justLabel.y, 'Check justLabel y');
	equals(0, justLabel.z, 'Check justLabel z');
    equals('N', justLabelXY.label, 'Check justLabelXY label');
	equals(10, justLabelXY.x, 'Check justLabelXY x');
	equals(10, justLabelXY.y, 'Check justLabelXY y');
	equals(0, justLabelXY.z, 'Check justLabelXY z');
    equals('N', entire.label, 'Check entire label');
	equals(10, entire.x, 'Check entire x');
	equals(10, entire.y, 'Check entire y');
	equals(10, entire.z, 'Check entire z');
});

test("Check Weird Labels", function(){
	expect(8);
	equals('C', new Atom('C ').label, 'Check space after');
	equals('C', new Atom(' C').label, 'Check space before');
	equals('C', new Atom(' C ').label, 'Check space before and after');
	equals('Fe', new Atom('F e').label, 'Check space in the middle');
	equals('Fe', new Atom(' F  e  ').label, 'Check spaces everywhere');
	equals('C', new Atom('NH').label, 'Check compound');
	equals('C', new Atom('Ph').label, 'Check non-element');
	equals('C', new Atom('das\[f34adfs').label, 'Check non-sensible');
});
	
test("Check Addition", function(){
	var p1 = new Atom('C', 13, 17, -2);
	var p2 = new Atom('C', -9, 44, -10);
	expect(6);
	p1.add3D(p2);
    equals(4, p1.x, 'Check p1.x');
	equals(61, p1.y, 'Check p1.y');
	equals(-12, p1.z, 'Check p1.z');
	p2.add3D(p1);
    equals(-5, p2.x, 'Check p2.x');
	equals(105, p2.y, 'Check p2.y');
	equals(-22, p2.z, 'Check p2.z');
});

test("Check Subtraction", function(){
	var p1 = new Atom('C', 13, 17, -2);
	var p2 = new Atom('C', -9, 44, -10);
	expect(6);
	p1.sub3D(p2);
    equals(22, p1.x, 'Check p1.x');
	equals(-27, p1.y, 'Check p1.y');
	equals(8, p1.z, 'Check p1.z');
	p2.sub3D(p1);
    equals(-31, p2.x, 'Check p2.x');
	equals(71, p2.y, 'Check p2.y');
	equals(-18, p2.z, 'Check p2.z');
});

test("Check Distance", function(){
	expect(4);
    equals(0, new Atom().distance3D(new Atom()), 'Check overlapping');
    equals(Math.sqrt(14), new Atom().distance3D(new Atom('C', 1,2,3)), 'Check basic 3D');
    equals(Math.sqrt(3), new Atom().distance3D(new Atom('C',1,1, 1)), 'Check 1-1-1-sqrt(3)');
    equals(10, new Atom().distance3D(new Atom(0,0,10)), 'Check linear');
});

test("Check Carbons are Hidden", function(){
	expect(8);
	var specs = new VisualSpecifications();
    ok(!new Atom().isLabelVisible(specs), 'Check Lone Carbon');
    ok(new Atom('N').isLabelVisible(specs), 'Check Nitrogen');
	var mol = new Molecule();
	mol.atoms[0] = new Atom();
	mol.atoms[1] = new Atom();
	mol.atoms[2] = new Atom();
	mol.bonds[0] = new Bond(mol.atoms[0],mol.atoms[1]);
	mol.bonds[1] = new Bond(mol.atoms[1],mol.atoms[2]);
	mol.check();
    ok(!mol.atoms[0].isLabelVisible(specs), 'Check first terminal Carbon of propane');
    ok(!mol.atoms[1].isLabelVisible(specs), 'Check central Carbon of propane');
    ok(!mol.atoms[2].isLabelVisible(specs), 'Check second terminal Carbon of propane');
	specs.atoms_displayTerminalCarbonLabels_2D = true;
    ok(mol.atoms[0].isLabelVisible(specs), 'Check first terminal Carbon of propane, should display');
    ok(!mol.atoms[1].isLabelVisible(specs), 'Check central Carbon of propane');
    ok(mol.atoms[2].isLabelVisible(specs), 'Check second terminal Carbon of propane, should display');
});

test("Check Coordination Numbers", function(){
	expect(6);
	var mol = new Molecule();
	mol.atoms[0] = new Atom();
	mol.atoms[1] = new Atom();
	mol.atoms[2] = new Atom();
	mol.bonds[0] = new Bond(mol.atoms[0],mol.atoms[1]);
	mol.bonds[1] = new Bond(mol.atoms[1],mol.atoms[2]);
	mol.check();
    equals(1, mol.atoms[0].coordinationNumber, 'Check first terminal Carbon of propane');
    equals(2, mol.atoms[1].coordinationNumber, 'Check central Carbon of propane');
    equals(1, mol.atoms[2].coordinationNumber, 'Check second terminal Carbon of propane');
	mol.bonds[0].bondOrder = 2;
	mol.check();
    equals(2, mol.atoms[0].coordinationNumber, 'Check first terminal Carbon of propene');
    equals(3, mol.atoms[1].coordinationNumber, 'Check central Carbon of propene');
    equals(1, mol.atoms[2].coordinationNumber, 'Check second terminal Carbon of propene');
});

test("Check Number of Bonds", function(){
	expect(6);
	var mol = new Molecule();
	mol.atoms[0] = new Atom();
	mol.atoms[1] = new Atom();
	mol.atoms[2] = new Atom();
	mol.bonds[0] = new Bond(mol.atoms[0],mol.atoms[1]);
	mol.bonds[1] = new Bond(mol.atoms[1],mol.atoms[2]);
	mol.check();
    equals(1, mol.atoms[0].coordinationNumber, 'Check first terminal Carbon of propane');
    equals(2, mol.atoms[1].coordinationNumber, 'Check central Carbon of propane');
    equals(1, mol.atoms[2].coordinationNumber, 'Check second terminal Carbon of propane');
	mol.bonds[0].bondOrder = 2;
    equals(1, mol.atoms[0].coordinationNumber, 'Check first terminal Carbon of propene');
    equals(2, mol.atoms[1].coordinationNumber, 'Check central Carbon of propene');
    equals(1, mol.atoms[2].coordinationNumber, 'Check second terminal Carbon of propene');
});