diff --git a/browser/js/compare.js b/browser/js/compare.js index 53e86a34978b132ea8b36845e58dec824459f340..d5c86dba20ca9b7844e61373e8b7aa97fcb344a1 100644 --- a/browser/js/compare.js +++ b/browser/js/compare.js @@ -42,41 +42,12 @@ var term = "*"; * Renvoie 1 si la deuxième chaîne doit être classée avant la première */ function compare(string1, string2) { - //Variable permettant l'incrémentation dans le TantQue - var i = 0; - //Vérification de la présence de l'étoile (pour la comparaison d'allèles) - var boolTerm = false; - //On réduit tout en minuscule, afin de faciliter la comparaison caractère par caractère... - var string1_lower = string1.toLowerCase(); - var string2_lower = string2.toLowerCase(); - //On sauvegarde le premier caractère de la phrase en minuscule - var charS1 = string1_lower.charAt(0); - var charS2 = string2_lower.charAt(0); - if (charS1 == term) { - charS1 = string1_lower.charAt(1); - boolTerm = true; - } - if (charS2 == term) { - charS2 = string2_lower.charAt(1); - boolTerm = true; - } - if (boolTerm === true) i = 1; - //On va trier les noms qui, pour l'instant, ne contiennent aucun nombre - var value_compare_ascii = 0; - while (value_compare_ascii === 0 && isNaN(charS1) && isNaN(charS2) && i string2 + var comparaison_2 = string1 < string2 + + if( comparaison_1){ return 1} + if( comparaison_2){ return -1} + return 0; } /* Fonction permettant la comparaison entre 2 caractères ascii diff --git a/browser/test/QUnit/testFiles/compare_test.js b/browser/test/QUnit/testFiles/compare_test.js new file mode 100644 index 0000000000000000000000000000000000000000..577d98b5dbc84977e5756f54de00561b5a42f908 --- /dev/null +++ b/browser/test/QUnit/testFiles/compare_test.js @@ -0,0 +1,49 @@ + + +QUnit.module("Compare", { +}); + + +QUnit.test("compare", function(assert) { + + // avec des valeurs identiques + // numbers + getted = compare("42", "42") + assert.equal(getted, 0, "identical number return 0") + // only string + getted = compare("intron-a", "intron-a") + assert.equal(getted, 0, "identical string return 0") + // string with number + getted = compare("intron-42", "intron-42") + assert.equal(getted, 0, "identical string+number retrun 0") + + // * Renvoie 0 si les deux chaînes sont strictement équivalentes + // * Renvoie -1 si la première chaîne doit être classée avant la deuxième + // * Renvoie 1 si la deuxième chaîne doit être classée avant la première + getted = compare("intron-1", "intron-1-var") + assert.equal(getted, -1, "string+number have correct return") + getted = compare("intron-1-var", "intron-1") + assert.equal(getted, 1, "reverse of the previous") + + getted = compare("intron-vax", "intron-var") + assert.equal(getted, 1, "string return correct order") + getted = compare("intron-1-var", "intron-1-vax") + assert.equal(getted, -1, "reverse of the previous") + + + + getted = compare("42", "512") + assert.equal(getted, -1, "number return correct order") + getted = compare("512", "42") + assert.equal(getted, 1, "reverse of the previous") + getted = compare("042", "512") + assert.equal(getted, -1, "number with 0 at first place return correct order") + getted = compare("512", "042") + assert.equal(getted, 1, "reverse of the previous") + + getted = compare("intron-42*42", "intron-512*42") + assert.equal(getted, -1, "straing, number + allele return correct order") + getted = compare("intron-512*42", "intron-42*42") + assert.equal(getted, 1, "reverse of the previous") + +}); diff --git a/browser/test/QUnit/test_Qunit.html b/browser/test/QUnit/test_Qunit.html index e9881fa8d22f3bbc4403eb36112496f9861cd50b..b71b912d9977907419ea42402e1d2f94cab1b1bd 100644 --- a/browser/test/QUnit/test_Qunit.html +++ b/browser/test/QUnit/test_Qunit.html @@ -114,5 +114,6 @@ +