Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb27778c

Browse files
Copilotmathiasrw
andcommitted
Use deepEqual in tests and simplify comparison functions
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
1 parentff390d4 commitb27778c

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

‎src/60range.js‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@
77
*/
88

99
// Helper functions for comparing values (including dates)
10+
// JavaScript's comparison operators work with valueOf() for both Date and Number types
1011
varcompareValues=function(a,b){
11-
// Handle Date objects explicitly
12-
if(ainstanceofDate&&binstanceofDate){
13-
returna.getTime()-b.getTime();
14-
}
15-
// For numbers and other comparable types
1612
if(a<b)return-1;
1713
if(a>b)return1;
1814
return0;
1915
};
2016

2117
varminValue=function(a,b){
22-
returncompareValues(a,b)<=0 ?a :b;
18+
returna<=b ?a :b;
2319
};
2420

2521
varmaxValue=function(a,b){
26-
returncompareValues(a,b)>=0 ?a :b;
22+
returna>=b ?a :b;
2723
};
2824

2925
// Range class to represent a range of values

‎test/test055-B.js‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@ describe('Test 055-B - PostgreSQL Range Types', function () {
1717

1818
it('A) Create integer ranges',function(){
1919
varr1=alasql('SELECT int4range(10, 20) as r')[0].r;
20-
assert(r1);
21-
assert.equal(r1.lower,10);
22-
assert.equal(r1.upper,20);
20+
assert.deepEqual(r1,{lower:10,upper:20,lowerInc:true,upperInc:false});
2321
});
2422

2523
it('B) Create numeric ranges',function(){
2624
varr1=alasql('SELECT numrange(11.1, 22.2) as r')[0].r;
27-
assert(r1);
28-
assert.equal(r1.lower,11.1);
29-
assert.equal(r1.upper,22.2);
25+
assert.deepEqual(r1,{lower:11.1,upper:22.2,lowerInc:true,upperInc:false});
3026
});
3127

3228
it('C) Create date ranges',function(){
@@ -73,16 +69,12 @@ describe('Test 055-B - PostgreSQL Range Types', function () {
7369

7470
it('J) Test range_union',function(){
7571
varr=alasql('SELECT range_union(int4range(10, 20), int4range(15, 25)) as r')[0].r;
76-
assert(r);
77-
assert.equal(r.lower,10);
78-
assert.equal(r.upper,25);
72+
assert.deepEqual(r,{lower:10,upper:25,lowerInc:true,upperInc:false});
7973
});
8074

8175
it('K) Test range_intersection',function(){
8276
varr=alasql('SELECT range_intersection(int4range(10, 20), int4range(15, 25)) as r')[0].r;
83-
assert(r);
84-
assert.equal(r.lower,15);
85-
assert.equal(r.upper,20);
77+
assert.deepEqual(r,{lower:15,upper:20,lowerInc:true,upperInc:false});
8678
});
8779

8880
it('L) Test range_intersection - no overlap returns null',function(){
@@ -92,10 +84,8 @@ describe('Test 055-B - PostgreSQL Range Types', function () {
9284

9385
it('M) Test range_difference',function(){
9486
varr=alasql('SELECT range_difference(int4range(10, 30), int4range(20, 40)) as r')[0].r;
95-
assert(r);
9687
// Difference should give [10, 20)
97-
assert.equal(r.lower,10);
98-
assert.equal(r.upper,20);
88+
assert.deepEqual(r,{lower:10,upper:20,lowerInc:true,upperInc:false});
9989
});
10090

10191
it('N) Use range in table and query',function(){
@@ -154,9 +144,7 @@ describe('Test 055-B - PostgreSQL Range Types', function () {
154144

155145
it('T) Test int8range (bigint range)',function(){
156146
varr=alasql('SELECT int8range(1000000, 2000000) as r')[0].r;
157-
assert(r);
158-
assert.equal(r.lower,1000000);
159-
assert.equal(r.upper,2000000);
147+
assert.deepEqual(r,{lower:1000000,upper:2000000,lowerInc:true,upperInc:false});
160148
});
161149

162150
it('U) Test tsrange (timestamp range)',function(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp