Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
vidjil
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1,412
Issues
1,412
List
Boards
Labels
Milestones
Merge Requests
49
Merge Requests
49
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vidjil
vidjil
Commits
a1c04369
Commit
a1c04369
authored
Jun 15, 2018
by
flothoni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compare.js: update function compare()
Use easiest comparaisons bettween two values. fix
#3288
parent
16a88095
Pipeline
#28678
passed with stages
in 6 minutes and 24 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
38 deletions
+56
-38
browser/js/compare.js
browser/js/compare.js
+6
-38
browser/test/QUnit/testFiles/compare_test.js
browser/test/QUnit/testFiles/compare_test.js
+49
-0
browser/test/QUnit/test_Qunit.html
browser/test/QUnit/test_Qunit.html
+1
-0
No files found.
browser/js/compare.js
View file @
a1c04369
...
...
@@ -42,44 +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
<
string1
.
length
&&
i
<
string2
.
length
)
{
value_compare_ascii
=
compare_ascii
(
charS1
,
charS2
);
i
++
;
charS1
=
string1_lower
.
charAt
(
i
);
charS2
=
string2_lower
.
charAt
(
i
);
}
if
(
value_compare_ascii
!==
0
){
return
value_compare_ascii
;
}
//Si l'on arrive ici, c'est qu'il n'y avait rien à comparer sur les chaînes de caractères précédemment données
//Vérification si l'un ou/et l'autre est/sont nul(s)
var
value_compare_length
=
compare_length
(
string1_lower
,
string2_lower
,
i
);
if
(
value_compare_length
===
undefined
)
{
return
compare_numbers
(
string1_lower
.
substring
(
i
,
string1
.
length
),
string2_lower
.
substring
(
i
,
string2
.
length
));
}
else
{
return
value_compare_length
;
}
var
comparaison_1
=
string1
>
string2
var
comparaison_2
=
string1
<
string2
if
(
!
comparaison_1
&&
!
comparaison_2
){
return
0
}
if
(
comparaison_1
&&
!
comparaison_2
){
return
1
}
if
(
!
comparaison_1
&&
comparaison_2
){
return
-
1
}
}
/* Fonction permettant la comparaison entre 2 caractères ascii
...
...
browser/test/QUnit/testFiles/compare_test.js
0 → 100644
View file @
a1c04369
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
"
)
});
browser/test/QUnit/test_Qunit.html
View file @
a1c04369
...
...
@@ -114,5 +114,6 @@
<script
src=
"./testFiles/shortcut_test.js"
></script>
<script
src=
"./testFiles/speed_test.js"
></script>
<script
src=
"./testFiles/tokeniser_test.js"
></script>
<script
src=
"./testFiles/compare_test.js"
></script>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment