Skip to content
Permalink
Browse files

Fixing #29

  • Loading branch information
samchon committed Nov 18, 2019
1 parent 80fa44e commit f1f5030ea2b5cce30181cdd505422e357066dc20
@@ -6,7 +6,7 @@
"email": "samchon@samchon.org",
"url": "http://samchon.org"
},
"version": "0.2.7",
"version": "0.3.0-dev.20191118",
"main": "index.js",
"typings": "index.d.ts",
"scripts": {
@@ -1,9 +1,9 @@
import { Communicator } from "../../components/Communicator";
import { Driver } from "../../components/Driver";
import { Communicator } from "../../../components/Communicator";
import { Driver } from "../../../components/Driver";

import { Calculator } from "../providers/Calculator";
import { ICalculator } from "../controllers/ICalculator";
import { Invoke } from "../../components/Invoke";
import { Calculator } from "../../providers/Calculator";
import { ICalculator } from "../../controllers/ICalculator";
import { Invoke } from "../../../components/Invoke";
import { InvalidArgument } from "tstl/exception/LogicError";

class PseudoCommunicator<Provider> extends Communicator<Provider>
@@ -1,8 +1,8 @@
import { WebServer } from "../../protocols/web/WebServer";
import { WebConnector } from "../../protocols/web/WebConnector";
import { WebServer } from "../../../protocols/web/WebServer";
import { WebConnector } from "../../../protocols/web/WebConnector";

import { Driver } from "../../components/Driver";
import { Calculator, Scientific } from "../providers/Calculator";
import { Driver } from "../../../components/Driver";
import { Calculator, Scientific } from "../../providers/Calculator";

class CustomCalculator extends Calculator
{
@@ -1,9 +1,10 @@
import { WebServer, WebConnector } from "../../../protocols/web";
import { Driver } from "../../../components"
import { WebServer } from "../../../../protocols/web/WebServer";
import { WebConnector } from "../../../../protocols/web/WebConnector";
import { Driver } from "../../../../components/Driver"

import { Calculator } from "../../providers/Calculator";
import { ICalculator } from "../../controllers/ICalculator";
import { IVector } from "../../controllers/IVector";
import { Calculator } from "../../../providers/Calculator";
import { ICalculator } from "../../../controllers/ICalculator";
import { IVector } from "../../../controllers/IVector";

import { Vector } from "tstl/container/Vector";

@@ -1,10 +1,10 @@
import { WebServer, WebConnector } from "../../../protocols/web";
import { Driver } from "../../../components";
import { WebServer, WebConnector } from "../../../../protocols/web";
import { Driver } from "../../../../components/Driver";

import { IScript } from "../../controllers/IScript";
import { IChatPrinter } from "../../controllers/IChatPrinter";
import { IChatService } from "../../controllers/IChatService";
import { ChatService } from "../../providers/ChatService";
import { IScript } from "../../../controllers/IScript";
import { IChatPrinter } from "../../../controllers/IChatPrinter";
import { IChatService } from "../../../controllers/IChatService";
import { ChatService } from "../../../providers/ChatService";

import { sleep_for } from "tstl/thread/global";

@@ -1,5 +1,5 @@
import { WebServer, WebConnector } from "../../../protocols/web";
import { Driver } from "../../../components/Driver";
import { WebServer, WebConnector } from "../../../../protocols/web";
import { Driver } from "../../../../components/Driver";

import { Vector } from "tstl/container/Vector";
import { Mutex } from "tstl/thread/Mutex";
@@ -86,10 +86,7 @@ export async function test_web_mutex(): Promise<void>

// ELEMENTS MUST BE SORTED BY THE CRITICAL SECTION
if (is_sorted(vector.begin(), vector.end()) === false)
{
console.log(vector.data());
throw new DomainError("remote mutex lock does not ensure the critical section.");
}

// CLOSE THE SERVER
await server.close();
@@ -1,5 +1,5 @@
import { WebServer } from "../../../protocols/web/WebServer";
import { WebConnector } from "../../../protocols/web/WebConnector";
import { WebServer } from "../../../../protocols/web/WebServer";
import { WebConnector } from "../../../../protocols/web/WebConnector";

const PORT = 10101;

@@ -1,8 +1,9 @@
import { WorkerServer, WorkerConnector } from "../../../../protocols/workers";
import { Driver } from "../../../../components";
import { WorkerServer } from "../../../../../protocols/workers/WorkerServer";
import { WorkerConnector } from "../../../../../protocols/workers/WorkerConnector";
import { Driver } from "../../../../../components/Driver";

import { Simple } from "../../../providers/Calculator";
import { IScientific, IStatistics } from "../../../controllers/ICalculator";
import { Simple } from "../../../../providers/Calculator";
import { IScientific, IStatistics } from "../../../../controllers/ICalculator";

class HierarchicalCalculator extends Simple
{
@@ -1,7 +1,7 @@
import { WorkerServer } from "../../../../protocols/workers";
import { IScript } from "../../../controllers/IScript";
import { Driver } from "../../../../components";
import { IChatService } from "../../../controllers/IChatService";
import { WorkerServer } from "../../../../../protocols/workers/WorkerServer";
import { IScript } from "../../../../controllers/IScript";
import { Driver } from "../../../../../components/Driver";
import { IChatService } from "../../../../controllers/IChatService";

import { sleep_for } from "tstl/thread/global";

@@ -1,5 +1,5 @@
import fs = require("fs");
import { WorkerServer } from "../../../../protocols/workers";
import { WorkerServer } from "../../../../../protocols/workers/WorkerServer";

const FILE_PATH = __dirname + "/../log.dat";

@@ -0,0 +1,9 @@
import { WorkerServer } from "../../../../../protocols/workers";
import { Scientific } from "../../../../providers/Calculator";

async function main(): Promise<void>
{
let server = new WorkerServer();
await server.open(new Scientific());
}
main();
@@ -0,0 +1,9 @@
import { WorkerServer } from "../../../../../protocols/workers";
import { Statistics } from "../../../../providers/Calculator";

async function main(): Promise<void>
{
let server = new WorkerServer();
await server.open(new Statistics());
}
main();
@@ -1,7 +1,7 @@
import { WorkerConnector } from "../../../protocols/workers";
import { Driver } from "../../../components";
import { WorkerConnector } from "../../../../protocols/workers";
import { Driver } from "../../../../components";

import { ICalculator } from "../../controllers/ICalculator";
import { ICalculator } from "../../../controllers/ICalculator";

export async function test_hierarchical_workers(): Promise<void>
{
File renamed without changes.
@@ -1,20 +1,20 @@
import fs = require("fs");
import cp = require("child_process");

import { WorkerConnector } from "../../../protocols/workers/WorkerConnector";
import { ICalculator } from "../../controllers/ICalculator";
import { WorkerConnector } from "../../../../protocols/workers/WorkerConnector";
import { ICalculator } from "../../../controllers/ICalculator";

export function test_worker_connect(): Promise<void>
{
return _Test_worker(worker =>
{
return worker.connect(__dirname + "/../../browser/worker-server.js", "first", "second");
return worker.connect(__dirname + "/../../../browser/worker-server.js", "first", "second");
});
}

export async function test_worker_compile(): Promise<void>
{
const PATH = __dirname + "/../../../bundle/worker-server.js";
const PATH = __dirname + "/../../../../bundle/worker-server.js";
if (fs.existsSync(PATH) === false)
cp.execSync("npm run bundle");

@@ -1,6 +1,6 @@
import { WorkerConnector } from "../../../protocols/workers";
import { WorkerConnector } from "../../../../protocols/workers";

import { FileSystem } from "../../../protocols/workers/internal/FileSystem";
import { FileSystem } from "../../../../protocols/workers/internal/FileSystem";
import { sleep_for } from "tstl/thread";

const FILE_PATH = __dirname + "/log.dat";
@@ -17,8 +17,7 @@ export async function test_worker_join(): Promise<void>

let content: string = await FileSystem.read(FILE_PATH, "utf8");
await FileSystem.unlink(FILE_PATH);

console.log(content);

if (content !== "WorkerServer.join()")
throw new Error("Error on WorkerServer.join()");
}
@@ -0,0 +1,103 @@
import { Entry } from "tstl/utility/Entry";
import { URLVariables } from "../../../utils/URLVariables";
import { DomainError, LengthError, InvalidArgument } from "tstl/exception/LogicError";
import { equal } from "tstl/algorithm/iterations";

type Element = Entry<string, string>;
interface IAuthor
{
name: string;
age: number;
git: string;
homepage: string;
memo: string;
is_crazy: boolean;

[key: string]: any;
}

function test_global(author: IAuthor): void
{
//----
// STRINGIFY & PARSE
//----
// STRINGIFY -> OBJECT TO URL-ENCODED STRING
let url_encoded_str: string = URLVariables.stringify(author);

// PARSE -> URL-ENCODED STRING TO OBJECT
let obj: IAuthor = URLVariables.parse(url_encoded_str, true);

//----
// VALIDATE
//----
// VALIDATE STRINGIFY
if (url_encoded_str !== URLVariables.stringify(obj))
throw new DomainError("Error on URLVariables.decode().");

// VALIDATE PARSE -> (AUTHOR === OBJ)?
for (let key in author)
if (author[key] !== obj[key])
throw new DomainError("Error on URLVariables.parse().");
}

function test_class(author: IAuthor): void
{
//----
// GENERATE URL-VARIABLES OBJECT
//----
let dict: URLVariables = new URLVariables();

// FILL ELEMENTS
dict.set("name", author.name);
dict.set("age", String(author.age)); // MUST BE STRING
dict.set("git", author.git);
dict.set("homepage", author.homepage);
dict.set("memo", author.memo);
dict.set("is_crazy", String(author.is_crazy));

// CONVERT THE URL-VARIABLES OBJECT TO URL-ENCODED STRING
let url_encoded_str: string = dict.toString();

//----
// VALIDATIONS
//----
// CREATE A NEW URL-VARIABLES OBJECT
// BY PARSING THE URL-ENCODED STRING
let vars: URLVariables = new URLVariables(url_encoded_str);

// VALIDATE SIZE
if (dict.size() !== vars.size())
throw new LengthError("Size are different.");

// ALL ELEMENTS ARE EQUAL
let equality: boolean = equal
(
dict.begin(), dict.end(), vars.begin(),
function (x: Element, y: Element): boolean
{
return x.first === y.first && x.second === y.second;
}
);
if (equality === false)
throw new InvalidArgument("Elements are different.");

// ALL ELEMENTS ARE EQUAL, THEN ENCODINGS MUST BE SAME
if (dict.toString() !== vars.toString())
throw new DomainError("Error on URLVariables.toString().");
}

export function test_url_variables(): void
{
let author: IAuthor =
{
name: "Samchon (Jeongho Nam)",
age: 29,
git: "https://github.com/samchon/tstl",
homepage: "http://samchon.org",
memo: "Hello, I'm the best programmer in Korea.",
is_crazy: true
};

test_global(author);
test_class(author);
}

0 comments on commit f1f5030

Please sign in to comment.
You can’t perform that action at this time.