This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/next by this push:
new 17f088a fix: [data-transform] (1) update the sort rule for string and
incomparable value. update test cases. (2) `parser: 'number'` supports suffix
parse (like '100%', '20px').
17f088a is described below
commit 17f088a75efdcddd69151773e1d7e25882abedaa
Author: 100pah <[email protected]>
AuthorDate: Fri Aug 14 22:48:33 2020 +0800
fix: [data-transform] (1) update the sort rule for string and incomparable
value. update test cases. (2) `parser: 'number'` supports suffix parse (like
'100%', '20px').
---
src/component/transform/sortTransform.ts | 4 +-
src/data/helper/dataValueHelper.ts | 54 +++++--
test/data-transform.html | 88 +++++++----
test/ut/spec/data/dataValueHelper.test.js | 251 +++++++++++++++---------------
4 files changed, 223 insertions(+), 174 deletions(-)
diff --git a/src/component/transform/sortTransform.ts
b/src/component/transform/sortTransform.ts
index 8f6f184..0583f1a 100644
--- a/src/component/transform/sortTransform.ts
+++ b/src/component/transform/sortTransform.ts
@@ -56,8 +56,8 @@ type OrderExpression = {
dimension: DimensionLoose;
order: 'asc' | 'desc';
parser?: RawValueParserType;
- // Value that is not comparable (like null/undefined) will be
- // put to head or tail.
+ // The meansing of "incomparable": see [SORT_COMPARISON_RULE]
+ // in `data/helper/dataValueHelper.ts`
incomparable?: 'min' | 'max';
};
diff --git a/src/data/helper/dataValueHelper.ts
b/src/data/helper/dataValueHelper.ts
index 07c98e0..98e36c8 100644
--- a/src/data/helper/dataValueHelper.ts
+++ b/src/data/helper/dataValueHelper.ts
@@ -82,7 +82,10 @@ export type RawValueParserType = 'number' | 'time' | 'trim';
type RawValueParser = (val: unknown) => unknown;
const valueParserMap = createHashMap<RawValueParser, RawValueParserType>({
'number': function (val): number {
- return numericToNumber(val);
+ // Do not use `numericToNumber` here. We have by defualt
`numericToNumber`.
+ // Here the number parser can have loose rule:
+ // enable to cut suffix: "120px" => 120, "14%" => 14.
+ return parseFloat(val as string);
},
'time': function (val): number {
// return timestamp.
@@ -143,6 +146,7 @@ export class SortOrderComparator {
* @param order by defualt: 'asc'
* @param incomparable by defualt: Always on the tail.
* That is, if 'asc' => 'max', if 'desc' => 'min'
+ * See the definition of "incomparable" in [SORT_COMPARISON_RULE]
*/
constructor(order: 'asc' | 'desc', incomparable: 'min' | 'max') {
const isDesc = order === 'desc';
@@ -152,6 +156,7 @@ export class SortOrderComparator {
}
this._incomparable = incomparable === 'min' ? -Infinity : Infinity;
}
+ // See [SORT_COMPARISON_RULE].
// Performance sensitive.
evaluate(lval: unknown, rval: unknown): -1 | 0 | 1 {
// Most cases is 'number', and typeof maybe 10 times faseter than
parseFloat.
@@ -159,23 +164,26 @@ export class SortOrderComparator {
const rvalTypeof = typeof rval;
let lvalFloat = lvalTypeof === 'number' ? lval : numericToNumber(lval);
let rvalFloat = rvalTypeof === 'number' ? rval : numericToNumber(rval);
- const lvalIncmpr = isNaN(lvalFloat as number);
- const rvalIncmpr = isNaN(rvalFloat as number);
- if (lvalIncmpr) {
+ const lvalNotNumeric = isNaN(lvalFloat as number);
+ const rvalNotNumeric = isNaN(rvalFloat as number);
+
+ if (lvalNotNumeric) {
lvalFloat = this._incomparable;
}
- if (rvalIncmpr) {
+ if (rvalNotNumeric) {
rvalFloat = this._incomparable;
}
- // In most cases, pure string sort has no meanings. But it can exists
when need to
- // group two categories (and order by anthor dimension meanwhile).
- // But if we support string sort, we still need to avoid the
misleading of `'2' > '12'`,
- // and support '-' means empty, and trade `'abc' > 2` as incomparable.
- // So we support string comparison only if both lval and rval are
string and not numeric.
- if (lvalIncmpr && rvalIncmpr && lvalTypeof === 'string' && rvalTypeof
=== 'string') {
- lvalFloat = lval;
- rvalFloat = rval;
+ if (lvalNotNumeric && rvalNotNumeric) {
+ const lvalIsStr = lvalTypeof === 'string';
+ const rvalIsStr = rvalTypeof === 'string';
+ if (lvalIsStr) {
+ lvalFloat = rvalIsStr ? lval : 0;
+ }
+ if (rvalIsStr) {
+ rvalFloat = lvalIsStr ? rval : 0;
+ }
}
+
return lvalFloat < rvalFloat ? this._resultLT
: lvalFloat > rvalFloat ? (-this._resultLT as -1 | 1)
: 0;
@@ -220,10 +228,24 @@ export type RelationalOperator = OrderRelationOperator |
'eq' | 'ne';
* `ne`:
* + Not `eq`.
*
+ *
* [SORT_COMPARISON_RULE]
- * Only `lt`|`gt`.
- * Always convert to number (`numericToNumer`) to compare.
- * (e.g., consider case: [12, " 13 ", " 14 ", null, 15])
+ * All the values are grouped into three categories:
+ * + "numeric" (number and numeric string)
+ * + "non-numeric-string" (string that excluding numeric string)
+ * + "others"
+ * "numeric" vs "numeric": values are ordered by number order.
+ * "non-numeric-string" vs "non-numeric-string": values are ordered by ES spec
(#sec-abstract-relational-comparison).
+ * "others" vs "others": do not change order (always return 0).
+ * "numeric" vs "non-numeric-string": "non-numeric-string" is treated as
"incomparable".
+ * "number" vs "others": "others" is treated as "incomparable".
+ * "non-numeric-string" vs "others": "others" is treated as "incomparable".
+ * "incomparable" will be seen as -Infinity or Infinity (depends on the
settings).
+ * MEMO:
+ * non-numeric string sort make sence when need to put the items with the
same tag together.
+ * But if we support string sort, we still need to avoid the misleading like
`'2' > '12'`,
+ * So we treat "numeric-string" sorted by number order rather than string
comparison.
+ *
*
* [CHECK_LIST_OF_THE_RULE_DESIGN]
* + Do not support string comparison until required. And also need to
diff --git a/test/data-transform.html b/test/data-transform.html
index 0f23efe..a5244ce 100644
--- a/test/data-transform.html
+++ b/test/data-transform.html
@@ -78,26 +78,27 @@ under the License.
var NAME_SCORE_DIM = {
Name: 0,
Age: 1,
- Sex: 2,
+ Profession: 2,
Score: 3,
Date: 4,
DirtyNumber: 5,
Numeric: 6,
- HasEmpty: 7
+ HasEmpty: 7,
+ Percent: 8
};
var NAME_SCORE_DIRTY_DATA_HEADER =
- ['Name', 'Age', 'Sex', 'Score', 'Date', 'DirtyNumber',
'Numeric', 'HasEmpty'];
+ ['Name', 'Age', 'Profession', 'Score', 'Date', 'DirtyNumber',
'Numeric', 'HasEmpty', 'Percent'];
var NAME_SCORE_DIRTY_DATA_NO_HEADER = [
// This is for trim testing.
- [' Jobs Mat ', 41, 'male', 314, '2011-02-12', '13', ' 91000 ',
45 ],
+ [' Jobs Mat ', 41, 'Designer', 314, '2011-02-12', '13', '
91000 ', 45, ' 12% ' ],
// This is for edge testing (03-01, 20)
- ['Hottlyuipe Xu ', 20, 'female', 351, '2011-03-01', 44, '
83000 ', 13 ],
- [' Jone Mat ', 52, 'male', 287, '2011-02-14', null, ' 43000 ',
null ],
- ['Uty Xu', 19, 'male', 219, '2011-02-18', undefined, ' 63000
', 81 ],
- ['Tatum von Godden', 25, 'female', 301, '2011-04-02', '-', '
13000 ', undefined ],
- ['Must Godden', 31, 'female', 235, '2011-03-19', ' 454', '-',
32 ],
- ['Caoas Xu', 71, 'male', 318, '2011-02-24', NaN, ' 73000 ',
'-' ],
- ['Malise Mat', 67, 'female', 366, '2011-03-12', '232a', '
23000 ', 19 ]
+ ['Hottlyuipe Xu ', 20, 'Engineer', 351, '2011-03-01', 44, '
83000 ', 13, '44%' ],
+ [' Jone Mat ', 52, 'Designer', 287, '2011-02-14', null, '
43000 ', null, '15%' ],
+ ['Uty Xu', 19, 'Designer', 219, '2011-02-18', undefined, '
63000 ', 81, '94%' ],
+ ['Tatum von Godden', 25, null, 301, '2011-04-02', '-', ' 13000
', undefined, '61%' ],
+ ['Must Godden', 31, 'Engineer', 235, '2011-03-19', ' 454',
'-', 32, '' ],
+ ['Caoas Xu', 71, 'Designer', 318, '2011-02-24', NaN, ' 73000
', '-', '76%' ],
+ ['Malise Mat', 67, 'Engineer', 366, '2011-03-12', '232a', '
23000 ', 19, '26%' ]
];
var NAME_SCORE_DIRTY_DATA_WITH_HEADER =
[NAME_SCORE_DIRTY_DATA_HEADER]
@@ -289,7 +290,7 @@ under the License.
NAME_SCORE_DIM.Name,
NAME_SCORE_DIM.Date,
NAME_SCORE_DIM.Score,
- NAME_SCORE_DIM.Sex,
+ NAME_SCORE_DIM.Profession,
NAME_SCORE_DIM.Age,
NAME_SCORE_DIM.DirtyNumber
]
@@ -363,15 +364,15 @@ under the License.
transform: {
type: 'filter',
// print: true,
- config: { dimension: NAME_SCORE_DIM.Sex, ne: 'male',
parser: 'trim' }
+ config: { dimension: NAME_SCORE_DIM.Profession, ne:
'Designer', parser: 'trim' }
}
});
addCartesian({
series: {
datasetId: 'e',
- encode: { label: [NAME_SCORE_DIM.Sex] }
+ encode: { label: [NAME_SCORE_DIM.Profession] }
},
- xAxis: { name: 'Show four points\n!male' }
+ xAxis: { name: 'Show four points\n!Designer' }
});
option.dataset.push({
@@ -381,7 +382,7 @@ under the License.
// print: true,
config: {
and: [
- { dimension: NAME_SCORE_DIM.Sex, eq: 'male',
parser: 'trim' },
+ { dimension: NAME_SCORE_DIM.Profession, eq:
'Designer', parser: 'trim' },
{ dimension: NAME_SCORE_DIM.Score, '>': 300 }
]
}
@@ -390,9 +391,9 @@ under the License.
addCartesian({
series: {
datasetId: 'f',
- encode: { label: [NAME_SCORE_DIM.Sex] }
+ encode: { label: [NAME_SCORE_DIM.Profession] }
},
- xAxis: { name: 'Show two points\nmale > 300' }
+ xAxis: { name: 'Show two points\nDesigner > 300' }
});
@@ -403,7 +404,7 @@ under the License.
// print: true,
config: {
and: [
- { dimension: NAME_SCORE_DIM.Sex, eq: 'female' },
+ { dimension: NAME_SCORE_DIM.Profession, eq:
'Engineer' },
{
or: [
{ dimension: NAME_SCORE_DIM.Age, '>=': 20,
'<=': 30 },
@@ -417,9 +418,9 @@ under the License.
addCartesian({
series: {
datasetId: 'g',
- encode: { label: [NAME_SCORE_DIM.Sex] }
+ encode: { label: [NAME_SCORE_DIM.Profession] }
},
- xAxis: { name: 'Show three points\nfemale && (20-30 || 60)' }
+ xAxis: { name: 'Show three points\nEngineer && (20-30 || 60)' }
});
option.dataset.push({
@@ -430,7 +431,7 @@ under the License.
config: {
not: {
and: [
- { dimension: NAME_SCORE_DIM.Sex, eq: 'female'
},
+ { dimension: NAME_SCORE_DIM.Profession, eq:
'Engineer' },
{
or: [
{ dimension: NAME_SCORE_DIM.Age, '>=':
20, '<=': 30 },
@@ -445,9 +446,9 @@ under the License.
addCartesian({
series: {
datasetId: 'h',
- encode: { label: [NAME_SCORE_DIM.Sex] }
+ encode: { label: [NAME_SCORE_DIM.Profession] }
},
- xAxis: { name: 'Show five points\n!(female && (20-30 || 60))' }
+ xAxis: { name: 'Show six points\n!(Engineer && (20-30 || 60))'
}
});
@@ -462,7 +463,7 @@ under the License.
addCartesian({
series: {
datasetId: 'i',
- encode: { label: [NAME_SCORE_DIM.Sex] }
+ encode: { label: [NAME_SCORE_DIM.Profession] }
},
xAxis: { name: 'Show all eight points\nconfig: true' }
});
@@ -580,11 +581,12 @@ under the License.
NAME_SCORE_DIM.Name,
NAME_SCORE_DIM.Date,
NAME_SCORE_DIM.Score,
- NAME_SCORE_DIM.Sex,
+ NAME_SCORE_DIM.Profession,
NAME_SCORE_DIM.Age,
NAME_SCORE_DIM.DirtyNumber,
NAME_SCORE_DIM.Numeric,
- NAME_SCORE_DIM.HasEmpty
+ NAME_SCORE_DIM.HasEmpty,
+ NAME_SCORE_DIM.Percent,
]
};
option.series.push(series);
@@ -629,7 +631,7 @@ under the License.
type: 'sort',
// print: true,
config: [
- { dimension: NAME_SCORE_DIM.Sex, order: 'asc' },
+ { dimension: NAME_SCORE_DIM.Profession, order: 'asc' },
{ dimension: NAME_SCORE_DIM.Score, order: 'desc' }
]
}
@@ -637,9 +639,15 @@ under the License.
addCartesian({
series: {
datasetId: 'c',
- encode: { label: [NAME_SCORE_DIM.Sex,
NAME_SCORE_DIM.Score] }
+ encode: { label: [NAME_SCORE_DIM.Profession,
NAME_SCORE_DIM.Score] }
},
- xAxis: { name: 'Show all eight bars\nSex asc (all female
left)\nScore desc in each Sex' }
+ xAxis: {
+ name: [
+ 'Show eight bars (empty Profession last)',
+ 'Profession asc (all Engineer left)',
+ 'Score desc in each Profession'
+ ].join('\n')
+ }
});
option.dataset.push({
@@ -752,6 +760,24 @@ under the License.
});
+ option.dataset.push({
+ id: 'j',
+ transform: {
+ type: 'sort',
+ config: [
+ { dimension: NAME_SCORE_DIM.Percent, order: 'desc',
parse: 'number' }
+ ]
+ }
+ });
+ addCartesian({
+ series: {
+ encode: { label: NAME_SCORE_DIM.Percent },
+ datasetId: 'j'
+ },
+ xAxis: { name: 'Show all eight bars\nOrder by Percent
desc\nempty at right' }
+ });
+
+
var chart = testHelper.create(echarts, 'main_cartesian_sort', {
title: [
'Test sort transform. Check each cartesians.',
@@ -759,7 +785,7 @@ under the License.
'Ordered dimension is on **bar label **'
],
width: chartWidth,
- height: 600,
+ height: 800,
option: option
});
});
diff --git a/test/ut/spec/data/dataValueHelper.test.js
b/test/ut/spec/data/dataValueHelper.test.js
index cf0c627..2ab3b30 100644
--- a/test/ut/spec/data/dataValueHelper.test.js
+++ b/test/ut/spec/data/dataValueHelper.test.js
@@ -25,29 +25,29 @@ const NO_SUCH_CASE = 'NO_SUCH_CASE';
// Tags for relational comparison cases.
// LT: less than, GT: greater than, INCMPR: incomparable
const TAG = {
- ONE_OR_TWO_NUMBER_L_LT_R: 'ONE_OR_TWO_NUMBER_L_LT_R',
- ONE_OR_TWO_NUMBER_L_GT_R: 'ONE_OR_TWO_NUMBER_L_GT_R',
- TWO_STRING_L_LT_R: 'TWO_STRING_L_LT_R',
- TWO_STRING_L_GT_R: 'TWO_STRING_L_GT_R',
- TWO_STRING_ONLY_NUMERIC_EQ: 'TWO_STRING_ONLY_NUMERIC_EQ',
- STRICT_EQ: 'STRICT_EQ',
- ONE_NUMBER_NUMERIC_EQ: 'ONE_NUMBER_NUMERIC_EQ',
- BOTH_INCMPR_NOT_EQ: 'BOTH_INCMPR_NOT_EQ',
- ONLY_L_INCMPR: 'ONLY_L_INCMPR',
- ONLY_R_INCMPR: 'ONLY_R_INCMPR'
+ BothNumeric_AtLeastOneNumber_L_LT_R: 'BothNumeric_AtLeastOneNumber_L_LT_R',
+ BothNumeric_AtLeastOneNumber_L_GT_R: 'BothNumeric_AtLeastOneNumber_L_GT_R',
+ BothString_L_LT_R: 'BothString_L_LT_R',
+ BothString_L_GT_R: 'BothString_L_GT_R',
+ BothNumericString_NotStrictEQ_BeNumericEQ:
'BothNumericString_NotStrictEQ_BeNumericEQ',
+ Strict_EQ: 'Strict_EQ',
+ BothNumeric_OneNumber_NumericEQ: 'BothNumeric_OneNumber_NumericEQ',
+ BothIncmpr_NotEQ: 'BothIncmpr_NotEQ',
+ L_Incmpr_R_NumberOrString: 'L_Incmpr_R_NumberOrString',
+ R_Incmpr_L_NumberOrString: 'R_Incmpr_L_NumberOrString'
};
const tagRevertPairs = [
- ['ONE_OR_TWO_NUMBER_L_LT_R', 'ONE_OR_TWO_NUMBER_L_GT_R'],
- ['TWO_STRING_L_LT_R', 'TWO_STRING_L_GT_R'],
- ['TWO_STRING_ONLY_NUMERIC_EQ', 'TWO_STRING_ONLY_NUMERIC_EQ'],
- ['STRICT_EQ', 'STRICT_EQ'],
- ['ONE_NUMBER_NUMERIC_EQ', 'ONE_NUMBER_NUMERIC_EQ'],
- ['BOTH_INCMPR_NOT_EQ', 'BOTH_INCMPR_NOT_EQ'],
- ['ONLY_L_INCMPR', 'ONLY_R_INCMPR']
+ ['BothNumeric_AtLeastOneNumber_L_LT_R',
'BothNumeric_AtLeastOneNumber_L_GT_R'],
+ ['BothString_L_LT_R', 'BothString_L_GT_R'],
+ ['BothNumericString_NotStrictEQ_BeNumericEQ',
'BothNumericString_NotStrictEQ_BeNumericEQ'],
+ ['Strict_EQ', 'Strict_EQ'],
+ ['BothNumeric_OneNumber_NumericEQ', 'BothNumeric_OneNumber_NumericEQ'],
+ ['BothIncmpr_NotEQ', 'BothIncmpr_NotEQ'],
+ ['L_Incmpr_R_NumberOrString', 'R_Incmpr_L_NumberOrString']
];
const filterResultMap = {
- ONE_OR_TWO_NUMBER_L_LT_R: {
+ BothNumeric_AtLeastOneNumber_L_LT_R: {
lt: true,
lte: true,
gt: false,
@@ -55,7 +55,7 @@ const filterResultMap = {
eq: false,
ne: true
},
- ONE_OR_TWO_NUMBER_L_GT_R: {
+ BothNumeric_AtLeastOneNumber_L_GT_R: {
lt: false,
lte: false,
gt: true,
@@ -63,7 +63,7 @@ const filterResultMap = {
eq: false,
ne: true
},
- TWO_STRING_L_LT_R: {
+ BothString_L_LT_R: {
lt: NO_SUCH_CASE,
lte: NO_SUCH_CASE,
gt: NO_SUCH_CASE,
@@ -71,7 +71,7 @@ const filterResultMap = {
eq: false,
ne: true
},
- TWO_STRING_L_GT_R: {
+ BothString_L_GT_R: {
lt: NO_SUCH_CASE,
lte: NO_SUCH_CASE,
gt: NO_SUCH_CASE,
@@ -79,7 +79,7 @@ const filterResultMap = {
eq: false,
ne: true
},
- TWO_STRING_ONLY_NUMERIC_EQ: {
+ BothNumericString_NotStrictEQ_BeNumericEQ: {
lt: NO_SUCH_CASE,
lte: NO_SUCH_CASE,
gt: NO_SUCH_CASE,
@@ -87,7 +87,7 @@ const filterResultMap = {
eq: false,
ne: true
},
- STRICT_EQ: {
+ Strict_EQ: {
lt: false,
lte: true,
gt: false,
@@ -95,7 +95,7 @@ const filterResultMap = {
eq: true,
ne: false
},
- ONE_NUMBER_NUMERIC_EQ: {
+ BothNumeric_OneNumber_NumericEQ: {
lt: false,
lte: true,
gt: false,
@@ -103,7 +103,7 @@ const filterResultMap = {
eq: true,
ne: false
},
- BOTH_INCMPR_NOT_EQ: {
+ BothIncmpr_NotEQ: {
lt: false,
lte: false,
gt: false,
@@ -111,7 +111,7 @@ const filterResultMap = {
eq: false,
ne: true
},
- ONLY_L_INCMPR: {
+ L_Incmpr_R_NumberOrString: {
lt: false,
lte: false,
gt: false,
@@ -119,7 +119,7 @@ const filterResultMap = {
eq: false,
ne: true
},
- ONLY_R_INCMPR: {
+ R_Incmpr_L_NumberOrString: {
lt: false,
lte: false,
gt: false,
@@ -130,61 +130,61 @@ const filterResultMap = {
};
const sortResultMap = {
- ONE_OR_TWO_NUMBER_L_LT_R: {
+ BothNumeric_AtLeastOneNumber_L_LT_R: {
asc_incmprmin: -1,
asc_incmprmax: -1,
desc_incmprmin: 1,
desc_incmprmax: 1
},
- ONE_OR_TWO_NUMBER_L_GT_R: {
+ BothNumeric_AtLeastOneNumber_L_GT_R: {
asc_incmprmin: 1,
asc_incmprmax: 1,
desc_incmprmin: -1,
desc_incmprmax: -1
},
- TWO_STRING_L_LT_R: {
+ BothString_L_LT_R: {
asc_incmprmin: -1,
asc_incmprmax: -1,
desc_incmprmin: 1,
desc_incmprmax: 1
},
- TWO_STRING_L_GT_R: {
+ BothString_L_GT_R: {
asc_incmprmin: 1,
asc_incmprmax: 1,
desc_incmprmin: -1,
desc_incmprmax: -1
},
- TWO_STRING_ONLY_NUMERIC_EQ: {
+ BothNumericString_NotStrictEQ_BeNumericEQ: {
asc_incmprmin: 0,
asc_incmprmax: 0,
desc_incmprmin: 0,
desc_incmprmax: 0
},
- STRICT_EQ: {
+ Strict_EQ: {
asc_incmprmin: 0,
asc_incmprmax: 0,
desc_incmprmin: 0,
desc_incmprmax: 0
},
- ONE_NUMBER_NUMERIC_EQ: {
+ BothNumeric_OneNumber_NumericEQ: {
asc_incmprmin: 0,
asc_incmprmax: 0,
desc_incmprmin: 0,
desc_incmprmax: 0
},
- BOTH_INCMPR_NOT_EQ: {
+ BothIncmpr_NotEQ: {
asc_incmprmin: 0,
asc_incmprmax: 0,
desc_incmprmin: 0,
desc_incmprmax: 0
},
- ONLY_L_INCMPR: {
+ L_Incmpr_R_NumberOrString: {
asc_incmprmin: -1,
asc_incmprmax: 1,
desc_incmprmin: 1,
desc_incmprmax: -1
},
- ONLY_R_INCMPR: {
+ R_Incmpr_L_NumberOrString: {
asc_incmprmin: 1,
asc_incmprmax: -1,
desc_incmprmin: -1,
@@ -201,100 +201,101 @@ function eachRelationalComparisonCase(evalFn) {
const testerMap = {
notEqualAndHasOrder: function () {
- expectDual(123, 555, TAG.ONE_OR_TWO_NUMBER_L_LT_R);
- expectDual(-123, -555, TAG.ONE_OR_TWO_NUMBER_L_GT_R);
- expectDual(-123, 123, TAG.ONE_OR_TWO_NUMBER_L_LT_R);
+ expectDual(123, 555, TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
+ expectDual(-123, -555, TAG.BothNumeric_AtLeastOneNumber_L_GT_R);
+ expectDual(-123, 123, TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
- expectDual(Infinity, 123, TAG.ONE_OR_TWO_NUMBER_L_GT_R);
- expectDual(-Infinity, -123, TAG.ONE_OR_TWO_NUMBER_L_LT_R);
- expectDual('Infinity', 123, TAG.ONE_OR_TWO_NUMBER_L_GT_R);
- expectDual('-Infinity', 123, TAG.ONE_OR_TWO_NUMBER_L_LT_R);
- expectDual(123, '555', TAG.ONE_OR_TWO_NUMBER_L_LT_R);
- expectDual(555, '555.6', TAG.ONE_OR_TWO_NUMBER_L_LT_R);
- expectDual('-555', -555.6, TAG.ONE_OR_TWO_NUMBER_L_GT_R);
- expectDual(123, ' 555 ', TAG.ONE_OR_TWO_NUMBER_L_LT_R);
- expectDual(' -555 ', 123, TAG.ONE_OR_TWO_NUMBER_L_LT_R);
- expectDual(123, ' \r \n 555 \t ' + FULL_WIDTH_SPACE,
TAG.ONE_OR_TWO_NUMBER_L_LT_R);
+ expectDual(Infinity, 123, TAG.BothNumeric_AtLeastOneNumber_L_GT_R);
+ expectDual(-Infinity, -123,
TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
+ expectDual('Infinity', 123,
TAG.BothNumeric_AtLeastOneNumber_L_GT_R);
+ expectDual('-Infinity', 123,
TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
+ expectDual(123, '555', TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
+ expectDual(555, '555.6', TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
+ expectDual('-555', -555.6,
TAG.BothNumeric_AtLeastOneNumber_L_GT_R);
+ expectDual(123, ' 555 ', TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
+ expectDual(' -555 ', 123, TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
+ expectDual(123, ' \r \n 555 \t ' + FULL_WIDTH_SPACE,
TAG.BothNumeric_AtLeastOneNumber_L_LT_R);
},
notEqualAndNoOrder: function () {
const makeDate = () => new Date(2012, 5, 12);
const makeFn = () => function () {};
- expectDual(NaN, NaN, TAG.BOTH_INCMPR_NOT_EQ);
- expectDual(NaN, -NaN, TAG.BOTH_INCMPR_NOT_EQ);
- expectDual(NaN, 0, TAG.ONLY_L_INCMPR);
- expectDual(NaN, 2, TAG.ONLY_L_INCMPR);
- expectDual('NaN', NaN, TAG.BOTH_INCMPR_NOT_EQ);
- expectDual('NaN', 0, TAG.ONLY_L_INCMPR);
- expectDual('NaN', 2, TAG.ONLY_L_INCMPR);
- expectDual('-NaN', -NaN, TAG.BOTH_INCMPR_NOT_EQ);
- expectDual('-NaN', 0, TAG.ONLY_L_INCMPR);
- expectDual('-NaN', 2, TAG.ONLY_L_INCMPR);
- expectDual(true, 0, TAG.ONLY_L_INCMPR);
- expectDual(false, 1, TAG.ONLY_L_INCMPR);
- expectDual('true', 0, TAG.ONLY_L_INCMPR);
- expectDual('false', 1, TAG.ONLY_L_INCMPR);
- expectDual(undefined, 2, TAG.ONLY_L_INCMPR);
- expectDual(undefined, 0, TAG.ONLY_L_INCMPR);
- expectDual(null, 2, TAG.ONLY_L_INCMPR);
- expectDual(null, 0, TAG.ONLY_L_INCMPR);
- expectDual(makeDate(), 0, TAG.ONLY_L_INCMPR);
- expectDual(makeDate(), makeDate(), TAG.BOTH_INCMPR_NOT_EQ);
- expectDual(makeDate(), +makeDate(), TAG.ONLY_L_INCMPR);
- expectDual([], 1, TAG.ONLY_L_INCMPR);
- expectDual([], 0, TAG.ONLY_L_INCMPR);
- expectDual({}, 1, TAG.ONLY_L_INCMPR);
- expectDual([], '0', TAG.ONLY_L_INCMPR);
- expectDual({}, '1', TAG.ONLY_L_INCMPR);
- expectDual({}, 0, TAG.ONLY_L_INCMPR);
- expectDual({}, '1', TAG.ONLY_L_INCMPR);
- expectDual({}, '0', TAG.ONLY_L_INCMPR);
- expectDual(/1/, 0, TAG.ONLY_L_INCMPR);
- expectDual(/0/, 0, TAG.ONLY_L_INCMPR);
- expectDual('555a', 123, TAG.ONLY_L_INCMPR);
- expectDual('abc', 123, TAG.ONLY_L_INCMPR);
- expectDual('abc', '123', TAG.ONLY_L_INCMPR);
- expectDual('abc', 'abcde', TAG.TWO_STRING_L_LT_R);
- expectDual('abc', 'abc', TAG.STRICT_EQ);
- expectDual('2', '12', TAG.TWO_STRING_L_LT_R); // '2' > '12' in JS
but should not happen here.
- expectDual(' ', '', TAG.TWO_STRING_L_GT_R);
- expectDual(0.5, '0. 5', TAG.ONLY_R_INCMPR);
- expectDual('0.5', '0. 5', TAG.ONLY_R_INCMPR);
- expectDual('- 5', -5, TAG.ONLY_L_INCMPR);
- expectDual('-123.5', ' -123.5 ', TAG.TWO_STRING_ONLY_NUMERIC_EQ);
- expectDual('0x11', 17, TAG.ONLY_L_INCMPR); // not 17 in int16.
- expectDual('0x11', 0, TAG.ONLY_L_INCMPR);
- expectDual('0x0', 0, TAG.ONLY_L_INCMPR);
- expectDual('0. 5', 0.5, TAG.ONLY_L_INCMPR);
- expectDual('0 .5', 0.5, TAG.ONLY_L_INCMPR);
- expectDual('', 2, TAG.ONLY_L_INCMPR);
- expectDual('', 0, TAG.ONLY_L_INCMPR);
- expectDual(' ', 2, TAG.ONLY_L_INCMPR);
- expectDual(' ', 0, TAG.ONLY_L_INCMPR);
- expectDual(' \n', '\n', TAG.TWO_STRING_L_GT_R);
- expectDual('\n', 0, TAG.ONLY_L_INCMPR);
- expectDual('\n', 2, TAG.ONLY_L_INCMPR);
- expectDual({}, {}, TAG.BOTH_INCMPR_NOT_EQ);
- expectDual({}, [], TAG.BOTH_INCMPR_NOT_EQ);
- expectDual(makeFn(), makeFn(), TAG.BOTH_INCMPR_NOT_EQ);
- expectDual(makeFn(), 0, TAG.ONLY_L_INCMPR);
- expectDual(makeFn(), 1, TAG.ONLY_L_INCMPR);
- expectDual(makeFn(), makeFn().toString(), TAG.BOTH_INCMPR_NOT_EQ);
+ expectDual(NaN, NaN, TAG.BothIncmpr_NotEQ);
+ expectDual(NaN, -NaN, TAG.BothIncmpr_NotEQ);
+ expectDual(NaN, 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(NaN, 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('NaN', NaN, TAG.R_Incmpr_L_NumberOrString);
+ expectDual('NaN', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('NaN', 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('-NaN', -NaN, TAG.R_Incmpr_L_NumberOrString);
+ expectDual('-NaN', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('-NaN', 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(true, 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(false, 1, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('true', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('false', 1, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(undefined, 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(undefined, 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(null, 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(null, 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(makeDate(), 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(makeDate(), makeDate(), TAG.BothIncmpr_NotEQ);
+ expectDual(makeDate(), +makeDate(), TAG.L_Incmpr_R_NumberOrString);
+ expectDual([], 1, TAG.L_Incmpr_R_NumberOrString);
+ expectDual([], 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual({}, 1, TAG.L_Incmpr_R_NumberOrString);
+ expectDual([], '0', TAG.L_Incmpr_R_NumberOrString);
+ expectDual({}, '1', TAG.L_Incmpr_R_NumberOrString);
+ expectDual({}, 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual({}, '1', TAG.L_Incmpr_R_NumberOrString);
+ expectDual({}, '0', TAG.L_Incmpr_R_NumberOrString);
+ expectDual(/1/, 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(/0/, 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('555a', 123, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('abc', 123, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('abc', null, TAG.R_Incmpr_L_NumberOrString); // See
[SORT_COMPARISON_RULE]
+ expectDual('abc', '123', TAG.L_Incmpr_R_NumberOrString);
+ expectDual('abc', 'abcde', TAG.BothString_L_LT_R);
+ expectDual('abc', 'abc', TAG.Strict_EQ);
+ expectDual('2', '12', TAG.BothString_L_LT_R); // '2' > '12' in JS
but should not happen here.
+ expectDual(' ', '', TAG.BothString_L_GT_R);
+ expectDual(0.5, '0. 5', TAG.R_Incmpr_L_NumberOrString);
+ expectDual('0.5', '0. 5', TAG.R_Incmpr_L_NumberOrString);
+ expectDual('- 5', -5, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('-123.5', ' -123.5 ',
TAG.BothNumericString_NotStrictEQ_BeNumericEQ);
+ expectDual('0x11', 17, TAG.L_Incmpr_R_NumberOrString); // not 17
in int16.
+ expectDual('0x11', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('0x0', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('0. 5', 0.5, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('0 .5', 0.5, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('', 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(' ', 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(' ', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(' \n', '\n', TAG.BothString_L_GT_R);
+ expectDual('\n', 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual('\n', 2, TAG.L_Incmpr_R_NumberOrString);
+ expectDual({}, {}, TAG.BothIncmpr_NotEQ);
+ expectDual({}, [], TAG.BothIncmpr_NotEQ);
+ expectDual(makeFn(), makeFn(), TAG.BothIncmpr_NotEQ);
+ expectDual(makeFn(), 0, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(makeFn(), 1, TAG.L_Incmpr_R_NumberOrString);
+ expectDual(makeFn(), makeFn().toString(),
TAG.L_Incmpr_R_NumberOrString);
},
equalNumeric: function () {
- expectDual(123, 123, TAG.STRICT_EQ);
- expectDual(1e3, 1000, TAG.STRICT_EQ);
- expectDual(-1e3, -1000, TAG.STRICT_EQ);
- expectDual('1e3', 1000, TAG.ONE_NUMBER_NUMERIC_EQ);
- expectDual('-1e3', -1000, TAG.ONE_NUMBER_NUMERIC_EQ);
- expectDual(123, '123', TAG.ONE_NUMBER_NUMERIC_EQ);
- expectDual(123, ' 123 ', TAG.ONE_NUMBER_NUMERIC_EQ);
- expectDual(123.5, ' \n \r 123.5 \t ', TAG.ONE_NUMBER_NUMERIC_EQ);
- expectDual(123.5, 123.5 + FULL_WIDTH_SPACE,
TAG.ONE_NUMBER_NUMERIC_EQ);
- expectDual(' -123.5 ', -123.5, TAG.ONE_NUMBER_NUMERIC_EQ);
- expectDual('011', 11, TAG.ONE_NUMBER_NUMERIC_EQ); // not 9 in int8.
+ expectDual(123, 123, TAG.Strict_EQ);
+ expectDual(1e3, 1000, TAG.Strict_EQ);
+ expectDual(-1e3, -1000, TAG.Strict_EQ);
+ expectDual('1e3', 1000, TAG.BothNumeric_OneNumber_NumericEQ);
+ expectDual('-1e3', -1000, TAG.BothNumeric_OneNumber_NumericEQ);
+ expectDual(123, '123', TAG.BothNumeric_OneNumber_NumericEQ);
+ expectDual(123, ' 123 ', TAG.BothNumeric_OneNumber_NumericEQ);
+ expectDual(123.5, ' \n \r 123.5 \t ',
TAG.BothNumeric_OneNumber_NumericEQ);
+ expectDual(123.5, 123.5 + FULL_WIDTH_SPACE,
TAG.BothNumeric_OneNumber_NumericEQ);
+ expectDual(' -123.5 ', -123.5,
TAG.BothNumeric_OneNumber_NumericEQ);
+ expectDual('011', 11, TAG.BothNumeric_OneNumber_NumericEQ); // not
9 in int8.
},
equalOtherTypes: function () {
@@ -302,10 +303,10 @@ function eachRelationalComparisonCase(evalFn) {
const emptyArr = [];
const date = new Date(2012, 5, 12);
const fn = function () {};
- expectDual(emptyObj, emptyObj, TAG.STRICT_EQ);
- expectDual(emptyArr, emptyArr, TAG.STRICT_EQ);
- expectDual(date, date, TAG.STRICT_EQ);
- expectDual(fn, fn, TAG.STRICT_EQ);
+ expectDual(emptyObj, emptyObj, TAG.Strict_EQ);
+ expectDual(emptyArr, emptyArr, TAG.Strict_EQ);
+ expectDual(date, date, TAG.Strict_EQ);
+ expectDual(fn, fn, TAG.Strict_EQ);
}
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]