Skip to content

Commit

Permalink
contribution guide and test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongho Nam committed Aug 13, 2017
1 parent 3352ac8 commit 25f9c0d
Show file tree
Hide file tree
Showing 28 changed files with 451 additions and 422 deletions.
5 changes: 2 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/src/test/index.js",
"program": "${workspaceRoot}/lib/test.js",
"cwd": "${workspaceRoot}",

// TypeScript
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/lib/*.js",
"${workspaceRoot}/src/test/*.js"
"${workspaceRoot}/lib/*.js"
]
},
{
Expand Down
111 changes: 111 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Contribution Guide
## Publishing a Issue
Thanks for your advise. Before publishing a issue, please check some components.

### 1. Search for duplicates
Before publishing a issue, please check whether the duplicated issue exists or not.
- [Ordinary Issues](https://github.com/samchon/tstl/issues)

### 2. Did you find a bug?
When you reporting a bug, then please write about those items:

- What version of TSTL you're using
- If possible, give me an isolated way to reproduce the behavior.
- The behavior your expect to see, and the actual behavior.

### 3. Do you have a suggestion?
I always welcome your suggestion. When you publishing a suggestion, then please write such items:

- A description of the problem you're trying to solve.
- An overview of the suggested solution.
- Examples of how the suggestion whould work in various places.
- Code examples showing the expected behavior.
- If relevant, precedent in C++/STL can be useful for establishing context and expected behavior.

## Contributing Code
### Test your code
Before sending a pull request, please test your new code. You go into the `build` directory and execute the `build.js`, then compiling your code and test-automation will be all processed.

```bash
tstl> node build/build
```

If you succeeded to compile, but failed to pass the test-automation, then *debug* the test-automation module. I've configured the `.vscode/launch.json`. You just run the `VSCode` and click the `Start Debugging` button or press `F5` key. By the *debugging*, find the reason why the *test* is failed and fix it.

### Adding a Test
If you want to add a testing-logic, then goto the `src/test` directory. It's the directory containing the test-automation module. Declare some functions starting from the prefix `test_`. Then, they will be called after the next testing.

Note that, the specific functions starting from the prefix `test_` must be delcared in the namespace of `test`. They also must return one of them:
- `void`
- `Promise<void>`

When you detect an error, then throw exception such below:

```typescript
namespace test
{
export function test_my_specific_logic1(): void
{
let vec = new std.Vector<number>();
for (let i: number = 0; i < 100; ++i)
vec.push_back(Math.random());

std.sort(vec.begin(), vec.end());

if (std.is_sorted(vec.begin(), vec.end()) == false)
throw new std.DomainError("std.sort doesn't work.");
}

export async function test_my_specific_logic2(): Promise<void>
{
let t1: Date = new Date();
await std.sleep_for(1000);

let t2: Date = new Date();
if (t2.getTime() - t1.getTime() < 1000)
throw new std.DomainError("std.sleep_for doesn't work.");
}
}
```

### Sending a Pull Request
Thanks for your contributing. Before sending a pull request to me, please check those components.

#### 1. Include enough descriptions
When you send a pull request, please include a description, of what your change intends to do, on the content. Title, make it clear and simple such below:
- Refactor features
- Fix issue #17
- Add tests for issue #28

#### 2. Include adequate tests
As I've mentioned in the `Contributing Code` section, your PR should pass the test-automation module. Your PR includes *new features* that have not being handled in the ordinary test-automation module, then also update *add the testing unit* please.

If there're some specific reasons that could not pass the test-automation (not error but *intended*), then please update the ordinary test-automation module or write the reasons on your PR content and *let me update the test-automation module*.

#### 3. Follow coding conventions
The basic coding convention of STL is the [`snake_case`](https://en.wikipedia.org/wiki/Snake_case). TypeScript-STL follows the basic coding convention; `snake_case`. However, there's a difference when naming the classes. TSTL uses `snake_case` and [`PascalCase`](https://en.wikipedia.org/wiki/PascalCase) on the classes at the same time.

```typescript
namespace std
{
export class Vector<T> // class base: PascalCase
{
// methods: snake_cases
public push_back(val: T): void;
public pop_back(): void;
}
export import vector = Vector; // class alias := snake_case

// global functions: snake_case
export function less_equal_to<T>(x: T, y: T): boolean;
export function sleep_until(at: Date): Promise<void>;
}
```

Thus, when you creating a new class, the make it to follow the [PascalCase] and make an alias following the `snake_case`. Methods in the classes or global functions, they just use the basic coding convention; `snake_case`.

- The detailed coding convention will be provided soon.

## References
I've referenced contribution guidance of TypeScript.
- https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md
84 changes: 3 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Below components are list of provided objects in the **T**ypeScript-**STL**. If
- [IComparable](http://samchon.github.io/tstl/api/interfaces/std.icomparable.html)
- [`<utility>`](http://www.cplusplus.com/reference/utility/)
- [Pair `pair`](http://samchon.github.io/tstl/api/classes/std.pair.html)

- [`<thread>`](https://github.com/samchon/tstl/tree/master/src/std/threads)
- sleep
- mutex


## Installation
Expand Down Expand Up @@ -99,86 +101,6 @@ Use [browserify](https://www.npmjs.com/package/browserify) or just include the *



## Differences between C++ STL
### Binary operator
```typescript
namepsace std
{
export interface IComparable<T>
{
equals(obj: T): boolean;

less?(obj: T): boolean;
hashCode?(): number;
}
}
```

### Iterator & Iteration
#### Operators
C++ STL | TypeScript-STL
------------------------|-----------------------
`Iterator.operator==()` | `Iterator.equals()`
`Iterator.operator*()` | `Iterator.value`
... | `MapIterator.first`
... | `MapIterator.second`

#### Advancing
C++ STL | TypeScript-STL
------------------|-----------------------
`it--` | `it = it.prev();`
`it++` | `it = it.next();`
`advance(it, 5);` | `it = it.advance(5);`

#### Sample Codes
##### C++ STL
```cpp
// Vector
std::vector<int> v(5, 1);
for (auto it = v.begin(); it != it.end(); ++it)
std::cout << *it << std::endl;

// TreeMap
std::map<int, std::string> m;
m.insert(std::make_pair(1, "first"));
m.insert({2, "second"});
m.emplace(3, "third");

m[4] = "fourth";
std::cout << m[4] << std::endl;

for (auto it = m.begin(); it != m.end(); ++it)
std::cout << it->first << ", " << it->second << std::endl;

for (auto &x : m) // NEW FEATURE, FULL-FORWARD-ITERATION
std::cout << x.first << ", " << x.second << std::endl;
```
##### TypeScript-STL
```typescript
// Vector
let v = new std.Vector<number>(5, 1);
for (let it = v.begin(); !it.equals(v.end()); it = it.next())
console.log(it.value);
// TreeMap
let m = new std.TreeMap<number, string>();
m.insert(std.make_pair(1, "first"));
m.insert([2, "second"]);
m.emplace(3, "third");
m.set(4, "fourth");
console.log(m.get(4));
for (let it = m.begin(); !it.equals(m.end()); it = it.next())
console.log(it.first, it.second); // TRADITIONAL ITERATION
for (let x of m) // NEW FEATURE, FULL-FORWARD ITERATION
console.log(x.first, x.second);
```



## References
- **Repositories**
- [GitHub Repository](https://github.com/samchon/tstl)
Expand Down
26 changes: 15 additions & 11 deletions build/build.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
const fs = require("fs");
const process = require('child_process');

// STD
compile();
attach_header();
remove_dynamics();

// TEST
test();

// MINIFY
minify();

function compile()
{
const STD_FILE = __dirname + "/../src/std/tsconfig.json";
const TEST_FILE = __dirname + "/../src/test/tsconfig.json";


// KEEP COMMENTS ONLY IN THE DECLARATION
process.execSync("tsc -p " + STD_FILE);
process.execSync("tsc -p " + STD_FILE + " --removeComments --declaration false");

// TESTING UNIT
process.execSync("tsc -p " + TEST_FILE);
}

function attach_header()
{
const TITLE_FILE = __dirname + "/../src/std/typings/tstl/tstl.d.ts";
const HEADER_FILE = __dirname + "/../lib/tstl.d.ts";
const HEAD = __dirname + "/../src/std/typings/tstl/tstl.d.ts";
const BODY = __dirname + "/../lib/tstl.d.ts";

var text = fs.readFileSync(TITLE_FILE, "utf8");
text += fs.readFileSync(HEADER_FILE, "utf8");
var text = fs.readFileSync(HEAD, "utf8");
text += fs.readFileSync(BODY, "utf8");

fs.writeFileSync(HEADER_FILE, text, "utf8");
fs.writeFileSync(BODY, text, "utf8");
}

function remove_dynamics()
Expand Down Expand Up @@ -65,7 +66,10 @@ function remove_dynamics()

function test()
{
process.execSync("node " + __dirname + "/../src/test/test");
const TEST_FILE = __dirname + "/../src/test/tsconfig.json";

process.execSync("tsc -p " + TEST_FILE);
process.execSync("node " + __dirname + "/../lib/test");
}

function minify()
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
"email": "[email protected]",
"url": "http://samchon.org"
},

"version": "1.5.6",
"main": "./lib/tstl.js",
"typings": "./lib/tstl.d.ts",
"version": "1.5.5",
"scripts": {
"test": "node lib/test"
},
"devDependencies": {
"@types/node": "^7.0.8"
},

"homepage": "https://github.com/samchon/tstl",
"repository": {
"type": "git",
Expand All @@ -26,6 +31,7 @@
"url": "https://opensource.org/licenses/BSD-3-Clause"
}
],

"keywords": [
"stl", "standard template library", "typescript", "standard", "template", "library",

Expand All @@ -34,10 +40,13 @@
"stack", "queue", "priority_queue",
"set", "multiset", "unordered_set", "unordered_multiset",
"map", "multimap", "unordered_map", "unordered_multimap",
"mutex", "thread",

"IComparable", "Pair", "PriorityQueue",
"TreeSet", "TreeMultiSet", "HashSet", "HashMultiSet",
"TreeMap", "TreeMultiMap", "HashMap", "HashMultiMap"
"TreeMap", "TreeMultiMap", "HashMap", "HashMultiMap",

"mutex", "thread", "sleep",
"TimedMutex", "SharedMutex", "SharedTimedMutex",
"timed_mutex", "shared_mutex", "shared_timed_mutex"
]
}
8 changes: 8 additions & 0 deletions src/std/containers/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,19 @@ namespace std

public constructor(...args: any[])
{
//----
// DEFAULT CONFIGURATIONS
//----
// INHERITS
super();

// DECLARE SOURCE POINTER
this.ptr_ = {value: this};
this["end_"]["source_ptr_"] = this.ptr_;

//----
// BRANCHES
//----
if (args.length == 0)
{
// DO NOTHING
Expand Down
2 changes: 1 addition & 1 deletion src/std/typings/tstl/tstl.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for TSTL v1.5.5
// Type definitions for TSTL v1.5.6
// Project: https://github.com/samchon/tstl
// Definitions by: Jeongho Nam <http://samchon.org>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down
31 changes: 19 additions & 12 deletions src/test/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@

eval('var std = require("./tstl")');

namespace example
namespace test
{
export function main(): void
export async function main(): Promise<void>
{
await std.sleep_for(0);
console.log("TEST ALL");

for (let key in example)
if (key != "main" && (example as any)[key] instanceof Function)
{
console.log("===================================================");
console.log(" " + key);
console.log("===================================================");
for (let key in test)
{
if (key.indexOf("test_") != 0)
continue;

(example as any)[key]();
console.log("\n");
}
console.log(key);
await test[key]();
}
}
}
module.exports = example;

test.main().then(() =>
{
console.log("No error has detected.");
}).catch(error =>
{
console.log(error);
throw error;
});
Loading

0 comments on commit 25f9c0d

Please sign in to comment.