-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Samchon
committed
Dec 24, 2019
1 parent
a13d64e
commit a27f503
Showing
22 changed files
with
319 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"email": "[email protected]", | ||
"url": "http://samchon.org" | ||
}, | ||
"version": "2.4.0-dev.20191223", | ||
"version": "2.4.0-dev.20191224", | ||
"main": "./index.js", | ||
"typings": "./index.d.ts", | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,62 @@ | ||
import * as std from "../../index"; | ||
import { Generator } from "../internal/Generator"; | ||
|
||
export function test_heaps(): void | ||
{ | ||
for (let i: number = 0; i < 100; ++i) | ||
{ | ||
let elems: std.Vector<number> = _Create_elements(); | ||
std.make_heap(elems.begin(), elems.end()); | ||
let elems: std.Vector<number> = Generator.fill(new std.Vector(), 100); | ||
std.ranges.make_heap(elems); | ||
|
||
if (std.is_heap(elems.begin(), elems.end()) === false) | ||
throw new std.DomainError("Error on std.push_heap() or std.is_heap()."); | ||
if (std.ranges.is_heap(elems) === false) | ||
throw new Error("Bug on std.push_heap() or std.is_heap()"); | ||
|
||
std.sort_heap(elems.begin(), elems.end()); | ||
if (std.is_sorted(elems.begin(), elems.end()) === false) | ||
throw new std.DomainError("Error on std.pop_heap()."); | ||
std.ranges.sort_heap(elems); | ||
if (std.ranges.is_sorted(elems) === false) | ||
throw new Error("Bug on std.pop_heap()"); | ||
} | ||
|
||
_Test_c_plus_plus(); | ||
_Test_cpp_reference(); | ||
} | ||
|
||
function _Create_elements(): std.Vector<number> | ||
{ | ||
let ret: std.Vector<number> = new std.Vector(); | ||
let size: number = std.randint(20, 80); | ||
|
||
for (let i: number = 0; i < size; ++i) | ||
ret.push_back(Math.random() * 100.0); | ||
|
||
return ret; | ||
} | ||
|
||
function _Test_c_plus_plus(): void | ||
{ | ||
let v: std.Vector<number> = new std.Vector([10, 20, 30, 5, 15]); | ||
|
||
std.make_heap(v.begin(), v.end()); | ||
if (v.front() !== 30 || std.is_heap(v.begin(), v.end()) === false) | ||
throw new std.DomainError("Error on std.make_heap()"); | ||
std.ranges.make_heap(v); | ||
if (v.front() !== 30 || std.ranges.is_heap(v) === false) | ||
throw new Error("Bug on std.make_heap()"); | ||
|
||
std.pop_heap(v.begin(), v.end()); | ||
std.ranges.pop_heap(v); | ||
v.pop_back(); | ||
if (v.front() !== 20) | ||
throw new std.DomainError("Error on std.pop_heap()"); | ||
throw new Error("Bug on std.pop_heap()"); | ||
|
||
v.push_back(99); | ||
std.push_heap(v.begin(), v.end()); | ||
std.ranges.push_heap(v); | ||
if (v.front() !== 99) | ||
throw new std.DomainError("Error on std.push_heap()"); | ||
throw new Error("Bug on std.push_heap()"); | ||
|
||
std.sort_heap(v.begin(), v.end()); | ||
if (std.is_sorted(v.begin(), v.end()) === false) | ||
throw new std.DomainError("Error on std.sort_heap()"); | ||
std.ranges.sort_heap(v); | ||
if (std.ranges.is_sorted(v) === false) | ||
throw new Error("Bug on std.sort_heap()"); | ||
} | ||
|
||
function _Test_cpp_reference(): void | ||
{ | ||
let v: std.Vector<number> = new std.Vector(); | ||
v.push(3, 1, 4, 1, 5, 9); | ||
|
||
std.make_heap(v.begin(), v.end()); | ||
if (std.equal(v.begin(), v.end(), std.begin(std.Vector.wrap([9, 5, 4, 1, 1, 3]))) === false) | ||
throw new std.DomainError("Error on std.make_heap()"); | ||
std.ranges.make_heap(v); | ||
if (std.ranges.equal(v, [9, 5, 4, 1, 1, 3]) === false) | ||
throw new Error("Bug on std.make_heap()"); | ||
|
||
std.pop_heap(v.begin(), v.end()); | ||
std.ranges.pop_heap(v); | ||
if (v.back() !== 9) | ||
throw new std.DomainError("Error on std.pop_heap()"); | ||
throw new Error("Bug on std.pop_heap()"); | ||
|
||
v.pop_back(); | ||
if (std.equal(v.begin(), v.end(), std.begin(std.Vector.wrap([5, 3, 4, 1, 1]))) === false) | ||
throw new std.DomainError("Error on std.pop_heap() & Vector.pop()"); | ||
if (std.ranges.equal(v, [5, 3, 4, 1, 1]) === false) | ||
throw new Error("Bug on std.pop_heap() & Vector.pop()"); | ||
} |
Oops, something went wrong.