trackler 2.2.1.29 → 2.2.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/common-lisp/docs/ABOUT.md +5 -10
- data/tracks/csharp/.gitignore +6 -8
- data/tracks/csharp/generators/Options.cs +1 -1
- data/tracks/csharp/generators/Program.cs +5 -1
- data/tracks/delphi/config.json +157 -157
- data/tracks/delphi/config/maintainers.json +11 -11
- data/tracks/delphi/exercises/circular-buffer/README.md +13 -6
- data/tracks/ecmascript/config.json +12 -0
- data/tracks/ecmascript/exercises/custom-set/custom-set.spec.js +198 -91
- data/tracks/ecmascript/exercises/custom-set/example.js +22 -31
- data/tracks/ecmascript/exercises/simple-linked-list/README.md +57 -0
- data/tracks/ecmascript/exercises/simple-linked-list/example.js +111 -0
- data/tracks/ecmascript/exercises/simple-linked-list/package.json +69 -0
- data/tracks/ecmascript/exercises/simple-linked-list/simple-linked-list.spec.js +146 -0
- data/tracks/go/.travis.yml +2 -2
- data/tracks/go/exercises/perfect-numbers/perfect_numbers_test.go +8 -0
- data/tracks/powershell/docs/INSTRUCTIONS.md +14 -0
- data/tracks/scala/exercises/variable-length-quantity/src/main/scala/{VariableLengthQuantity.scala → .keep} +0 -0
- data/tracks/scala/exercises/variable-length-quantity/src/test/scala/VariableLengthQuantityTest.scala +73 -82
- data/tracks/scala/testgen/src/main/scala/VariableLengthQuantityTestGenerator.scala +58 -59
- metadata +8 -3
@@ -0,0 +1,57 @@
|
|
1
|
+
# Simple Linked List
|
2
|
+
|
3
|
+
Write a simple linked list implementation that uses Elements and a List.
|
4
|
+
|
5
|
+
The linked list is a fundamental data structure in computer science,
|
6
|
+
often used in the implementation of other data structures. They're
|
7
|
+
pervasive in functional programming languages, such as Clojure, Erlang,
|
8
|
+
or Haskell, but far less common in imperative languages such as Ruby or
|
9
|
+
Python.
|
10
|
+
|
11
|
+
The simplest kind of linked list is a singly linked list. Each element in the
|
12
|
+
list contains data and a "next" field pointing to the next element in the list
|
13
|
+
of elements.
|
14
|
+
|
15
|
+
This variant of linked lists is often used to represent sequences or
|
16
|
+
push-down stacks (also called a LIFO stack; Last In, First Out).
|
17
|
+
|
18
|
+
As a first take, lets create a singly linked list to contain the range (1..10),
|
19
|
+
and provide functions to reverse a linked list and convert to and from arrays.
|
20
|
+
|
21
|
+
When implementing this in a language with built-in linked lists,
|
22
|
+
implement your own abstract data type.
|
23
|
+
|
24
|
+
## Setup
|
25
|
+
|
26
|
+
Go through the setup instructions for ECMAScript to
|
27
|
+
install the necessary dependencies:
|
28
|
+
|
29
|
+
http://exercism.io/languages/ecmascript
|
30
|
+
|
31
|
+
## Requirements
|
32
|
+
|
33
|
+
Install assignment dependencies:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
$ npm install
|
37
|
+
```
|
38
|
+
|
39
|
+
## Making the test suite pass
|
40
|
+
|
41
|
+
Execute the tests with:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
$ npm test
|
45
|
+
```
|
46
|
+
|
47
|
+
In the test suites all tests but the first have been skipped.
|
48
|
+
|
49
|
+
Once you get a test passing, you can enable the next one by
|
50
|
+
changing `xtest` to `test`.
|
51
|
+
|
52
|
+
## Source
|
53
|
+
|
54
|
+
Inspired by 'Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby', singly linked-lists. [http://www.brpreiss.com/books/opus8/html/page96.html#SECTION004300000000000000000](http://www.brpreiss.com/books/opus8/html/page96.html#SECTION004300000000000000000)
|
55
|
+
|
56
|
+
## Submitting Incomplete Solutions
|
57
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,111 @@
|
|
1
|
+
export class ElementValueRequiredException extends Error {}
|
2
|
+
export class ElementNextNotInstanceException extends Error {}
|
3
|
+
|
4
|
+
export class Element {
|
5
|
+
constructor(value, next) {
|
6
|
+
if (value === undefined) {
|
7
|
+
throw new ElementValueRequiredException();
|
8
|
+
}
|
9
|
+
|
10
|
+
if (next !== undefined && !(next instanceof Element)) {
|
11
|
+
throw new ElementNextNotInstanceException();
|
12
|
+
}
|
13
|
+
|
14
|
+
this.value = value;
|
15
|
+
this.next = next;
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
export class List {
|
20
|
+
static fromArray(array) {
|
21
|
+
const list = new List();
|
22
|
+
array.forEach(item => list.push(new Element(item)));
|
23
|
+
|
24
|
+
return list;
|
25
|
+
}
|
26
|
+
|
27
|
+
push(value) {
|
28
|
+
const newEl = (value instanceof Element)
|
29
|
+
? value
|
30
|
+
: new Element(value);
|
31
|
+
|
32
|
+
if (!this.head) {
|
33
|
+
this.head = newEl;
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
let lastEl = this.head;
|
38
|
+
while (lastEl.next) {
|
39
|
+
lastEl = lastEl.next;
|
40
|
+
}
|
41
|
+
|
42
|
+
lastEl.next = newEl;
|
43
|
+
}
|
44
|
+
|
45
|
+
unshift(value) {
|
46
|
+
const newEl = (value instanceof Element)
|
47
|
+
? value
|
48
|
+
: new Element(value);
|
49
|
+
|
50
|
+
newEl.next = this.head;
|
51
|
+
this.head = newEl;
|
52
|
+
}
|
53
|
+
|
54
|
+
shift() {
|
55
|
+
if (!this.head) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
this.head = this.head.next;
|
60
|
+
}
|
61
|
+
|
62
|
+
pop() {
|
63
|
+
if (!this.head) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
|
67
|
+
let penultEl;
|
68
|
+
let lastEl = this.head;
|
69
|
+
|
70
|
+
while (lastEl.next) {
|
71
|
+
penultEl = lastEl;
|
72
|
+
lastEl = lastEl.next;
|
73
|
+
}
|
74
|
+
|
75
|
+
if (!penultEl) {
|
76
|
+
this.head = undefined;
|
77
|
+
} else {
|
78
|
+
penultEl.next = undefined;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
reverse() {
|
83
|
+
if (!this.head) {
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
|
87
|
+
let current;
|
88
|
+
let previous;
|
89
|
+
|
90
|
+
while (this.head) {
|
91
|
+
current = this.head;
|
92
|
+
this.shift();
|
93
|
+
current.next = previous;
|
94
|
+
previous = current;
|
95
|
+
}
|
96
|
+
|
97
|
+
this.head = previous;
|
98
|
+
}
|
99
|
+
|
100
|
+
toArray() {
|
101
|
+
const array = [];
|
102
|
+
let current = this.head;
|
103
|
+
|
104
|
+
while (current) {
|
105
|
+
array.push(current.value);
|
106
|
+
current = current.next;
|
107
|
+
}
|
108
|
+
|
109
|
+
return array;
|
110
|
+
}
|
111
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
{
|
2
|
+
"name": "xecmascript",
|
3
|
+
"version": "0.0.0",
|
4
|
+
"description": "Exercism exercises in ECMAScript 6.",
|
5
|
+
"author": "Katrina Owen",
|
6
|
+
"private": true,
|
7
|
+
"repository": {
|
8
|
+
"type": "git",
|
9
|
+
"url": "https://github.com/exercism/xecmascript"
|
10
|
+
},
|
11
|
+
"devDependencies": {
|
12
|
+
"babel-jest": "^20.0.3",
|
13
|
+
"babel-plugin-transform-builtin-extend": "^1.1.2",
|
14
|
+
"babel-preset-env": "^1.4.0",
|
15
|
+
"eslint": "^3.19.0",
|
16
|
+
"eslint-config-airbnb": "^15.0.1",
|
17
|
+
"eslint-plugin-import": "^2.2.0",
|
18
|
+
"eslint-plugin-jsx-a11y": "^5.0.1",
|
19
|
+
"eslint-plugin-react": "^7.0.1",
|
20
|
+
"jest": "^20.0.4"
|
21
|
+
},
|
22
|
+
"jest": {
|
23
|
+
"modulePathIgnorePatterns": [
|
24
|
+
"package.json"
|
25
|
+
]
|
26
|
+
},
|
27
|
+
"babel": {
|
28
|
+
"presets": [
|
29
|
+
"env"
|
30
|
+
],
|
31
|
+
"plugins": [
|
32
|
+
[
|
33
|
+
"babel-plugin-transform-builtin-extend",
|
34
|
+
{
|
35
|
+
"globals": [
|
36
|
+
"Error"
|
37
|
+
]
|
38
|
+
}
|
39
|
+
],
|
40
|
+
["transform-regenerator"]
|
41
|
+
]
|
42
|
+
},
|
43
|
+
"scripts": {
|
44
|
+
"test": "jest --no-cache ./*",
|
45
|
+
"watch": "jest --no-cache --watch ./*",
|
46
|
+
"lint": "eslint .",
|
47
|
+
"lint-test": "eslint . && jest --no-cache ./* "
|
48
|
+
},
|
49
|
+
"eslintConfig": {
|
50
|
+
"parserOptions": {
|
51
|
+
"ecmaVersion": 6,
|
52
|
+
"sourceType": "module"
|
53
|
+
},
|
54
|
+
"env": {
|
55
|
+
"es6": true,
|
56
|
+
"node": true,
|
57
|
+
"jest": true
|
58
|
+
},
|
59
|
+
"extends": "airbnb",
|
60
|
+
"rules": {
|
61
|
+
"import/no-unresolved": "off",
|
62
|
+
"import/extensions": "off"
|
63
|
+
}
|
64
|
+
},
|
65
|
+
"licenses": [
|
66
|
+
"MIT"
|
67
|
+
],
|
68
|
+
"dependencies": {}
|
69
|
+
}
|
@@ -0,0 +1,146 @@
|
|
1
|
+
import {
|
2
|
+
List,
|
3
|
+
Element,
|
4
|
+
ElementValueRequiredException,
|
5
|
+
ElementNextNotInstanceException,
|
6
|
+
} from './simple-linked-list';
|
7
|
+
|
8
|
+
describe('simple-linked-list', () => {
|
9
|
+
test('exports a List constructor', () => {
|
10
|
+
expect(List).toBeDefined();
|
11
|
+
});
|
12
|
+
|
13
|
+
xtest('exports a Element constructor', () => {
|
14
|
+
expect(Element).toBeDefined();
|
15
|
+
});
|
16
|
+
|
17
|
+
describe('Element', () => {
|
18
|
+
xtest('is a constructor', () => {
|
19
|
+
const el = new Element(1);
|
20
|
+
expect(el).toBeDefined();
|
21
|
+
|
22
|
+
expect(() => {
|
23
|
+
Element(1);
|
24
|
+
}).toThrow();
|
25
|
+
});
|
26
|
+
|
27
|
+
xtest('requires an argument', () => {
|
28
|
+
const el = new Element(1);
|
29
|
+
expect(el).toBeDefined();
|
30
|
+
|
31
|
+
expect(() => new Element()).toThrow(ElementValueRequiredException);
|
32
|
+
});
|
33
|
+
|
34
|
+
xtest('has as a value', () => {
|
35
|
+
const el = new Element(1);
|
36
|
+
expect(el.value).toBe(1);
|
37
|
+
});
|
38
|
+
|
39
|
+
xtest('reference to next is undefined by default', () => {
|
40
|
+
const el = new Element(1);
|
41
|
+
expect(el.next).toBeUndefined();
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
xtest('accepts a reference to the next element', () => {
|
46
|
+
const elOne = new Element(1);
|
47
|
+
const elTwo = new Element(2, elOne);
|
48
|
+
expect(elTwo.next).toBe(elOne);
|
49
|
+
});
|
50
|
+
|
51
|
+
xtest('requires an instance of Element as next element', () => {
|
52
|
+
expect(() => new Element(1, true)).toThrow(ElementNextNotInstanceException);
|
53
|
+
expect(() => new Element(1, 'lorem ipsum')).toThrow(ElementNextNotInstanceException);
|
54
|
+
expect(() => new Element(1, [])).toThrow(ElementNextNotInstanceException);
|
55
|
+
expect(() => new Element(1, {})).toThrow(ElementNextNotInstanceException);
|
56
|
+
});
|
57
|
+
|
58
|
+
describe('List', () => {
|
59
|
+
xtest('is a constructor', () => {
|
60
|
+
const ll = new List();
|
61
|
+
expect(ll).toBeDefined();
|
62
|
+
});
|
63
|
+
|
64
|
+
xtest('allows you to append an element', () => {
|
65
|
+
const ll = new List();
|
66
|
+
const el = new Element(1);
|
67
|
+
ll.push(el);
|
68
|
+
expect(ll.head).toBe(el);
|
69
|
+
|
70
|
+
const ll2 = new List();
|
71
|
+
const elOne = new Element(1);
|
72
|
+
const elTwo = new Element(2);
|
73
|
+
ll2.push(elOne);
|
74
|
+
ll2.push(elTwo);
|
75
|
+
expect(ll2.head.next).toBe(elTwo);
|
76
|
+
});
|
77
|
+
|
78
|
+
xtest('allows you to prepend an element', () => {
|
79
|
+
const ll = new List();
|
80
|
+
const el = new Element(1);
|
81
|
+
ll.unshift(el);
|
82
|
+
expect(ll.head).toBe(el);
|
83
|
+
|
84
|
+
const ll2 = new List();
|
85
|
+
const elOne = new Element(1);
|
86
|
+
const elTwo = new Element(2);
|
87
|
+
ll2.unshift(elOne);
|
88
|
+
ll2.unshift(elTwo);
|
89
|
+
expect(ll2.head).toBe(elTwo);
|
90
|
+
});
|
91
|
+
|
92
|
+
xtest('allows you to remove the first element', () => {
|
93
|
+
const ll = new List();
|
94
|
+
ll.push(new Element(1));
|
95
|
+
ll.shift();
|
96
|
+
expect(ll.head).toBeUndefined();
|
97
|
+
|
98
|
+
ll.push(new Element(2));
|
99
|
+
ll.push(new Element(3));
|
100
|
+
ll.shift();
|
101
|
+
expect(ll.head.value).toBe(3);
|
102
|
+
});
|
103
|
+
|
104
|
+
xtest('allows you to remove the last element', () => {
|
105
|
+
const ll = new List();
|
106
|
+
ll.push(new Element(1));
|
107
|
+
ll.pop();
|
108
|
+
expect(ll.head).toBeUndefined();
|
109
|
+
|
110
|
+
ll.push(new Element(2));
|
111
|
+
ll.push(new Element(3));
|
112
|
+
ll.pop();
|
113
|
+
expect(ll.head.next).toBeUndefined();
|
114
|
+
});
|
115
|
+
|
116
|
+
xtest('allows you to convert an array to a List', () => {
|
117
|
+
const ll = List.fromArray([1, 2]);
|
118
|
+
|
119
|
+
expect(ll.head.value).toBe(1);
|
120
|
+
expect(ll.head.next.value).toBe(2);
|
121
|
+
});
|
122
|
+
|
123
|
+
xtest('allows you to convert a List into an array', () => {
|
124
|
+
const ll = new List();
|
125
|
+
ll.push(new Element(1));
|
126
|
+
ll.push(new Element(2));
|
127
|
+
const a = ll.toArray();
|
128
|
+
|
129
|
+
expect(a instanceof Array).toBe(true);
|
130
|
+
expect(a.length).toBe(2);
|
131
|
+
expect(a[0]).toBe(1);
|
132
|
+
expect(a[1]).toBe(2);
|
133
|
+
|
134
|
+
expect(ll.head.value).toBe(1);
|
135
|
+
});
|
136
|
+
|
137
|
+
xtest('allows you to reverse a List', () => {
|
138
|
+
const ll = List.fromArray([1, 2, 3]);
|
139
|
+
ll.reverse();
|
140
|
+
|
141
|
+
expect(ll.head.value).toBe(3);
|
142
|
+
expect(ll.head.next.value).toBe(2);
|
143
|
+
expect(ll.head.next.next.value).toBe(1);
|
144
|
+
});
|
145
|
+
});
|
146
|
+
});
|
data/tracks/go/.travis.yml
CHANGED
@@ -18,8 +18,8 @@ sudo: false
|
|
18
18
|
# but since Travis only runs five jobs at a time throughout all of Exercism,
|
19
19
|
# it is better citizenship to not test the additional versions.
|
20
20
|
go:
|
21
|
-
- 1.
|
22
|
-
- 1.
|
21
|
+
- 1.8.3
|
22
|
+
- 1.9
|
23
23
|
- tip
|
24
24
|
|
25
25
|
# Travis runs in a 64 bit environment but beginning with Go 1.5, building a
|
@@ -0,0 +1,14 @@
|
|
1
|
+
### Installing Windows PowerShell
|
2
|
+
|
3
|
+
PowerShell comes pre-installed on all Windows operating systems from Windows 7 SP1 onward.
|
4
|
+
|
5
|
+
You can find the latest version of PowerShell and installation instructions for all platforms [here](https://github.com/PowerShell/PowerShell/blob/master/README.md#get-powershell).
|
6
|
+
|
7
|
+
### Using an IDE
|
8
|
+
|
9
|
+
If you want a more full-featured editing experience, you probably want to use an IDE. These are the most popular IDE's that support building PowerShell projects:
|
10
|
+
|
11
|
+
##### All platforms
|
12
|
+
* [Visual Studio Code](https://code.visualstudio.com/download) with the [PowerShell extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell)
|
13
|
+
* [Atom](https://atom.io/) with the [PowerShell package](https://atom.io/packages/language-powershell)
|
14
|
+
* [Sublime Text 3](https://www.sublimetext.com/3) with the [PowerShell package](https://packagecontrol.io/packages/PowerShell)
|
File without changes
|
data/tracks/scala/exercises/variable-length-quantity/src/test/scala/VariableLengthQuantityTest.scala
CHANGED
@@ -1,162 +1,153 @@
|
|
1
|
-
import org.scalatest.{
|
1
|
+
import org.scalatest.{Matchers, FunSuite}
|
2
2
|
|
3
|
+
/** @version 1.0.0 */
|
3
4
|
class VariableLengthQuantityTest extends FunSuite with Matchers {
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
val encoded = VariableLengthQuantity.encode(List(0x0))
|
8
|
-
encoded should be (List(0x0))
|
6
|
+
test("zero") {
|
7
|
+
VariableLengthQuantity.encode(List(0x0)) should be(List(0x0))
|
9
8
|
}
|
10
9
|
|
11
|
-
test("
|
10
|
+
test("arbitrary single byte") {
|
12
11
|
pending
|
13
|
-
|
14
|
-
encoded should be (List(0x40))
|
12
|
+
VariableLengthQuantity.encode(List(0x40)) should be(List(0x40))
|
15
13
|
}
|
16
14
|
|
17
|
-
test("
|
15
|
+
test("largest single byte") {
|
18
16
|
pending
|
19
|
-
|
20
|
-
encoded should be (List(0x7f))
|
17
|
+
VariableLengthQuantity.encode(List(0x7F)) should be(List(0x7F))
|
21
18
|
}
|
22
19
|
|
23
|
-
test("
|
20
|
+
test("smallest double byte") {
|
24
21
|
pending
|
25
|
-
|
26
|
-
encoded should be (List(0x81, 0x0))
|
22
|
+
VariableLengthQuantity.encode(List(0x80)) should be(List(0x81, 0x0))
|
27
23
|
}
|
28
24
|
|
29
|
-
test("
|
25
|
+
test("arbitrary double byte") {
|
30
26
|
pending
|
31
|
-
|
32
|
-
encoded should be (List(0xc0, 0x0))
|
27
|
+
VariableLengthQuantity.encode(List(0x2000)) should be(List(0xC0, 0x0))
|
33
28
|
}
|
34
29
|
|
35
|
-
test("
|
30
|
+
test("largest double byte") {
|
36
31
|
pending
|
37
|
-
|
38
|
-
encoded should be (List(0xff, 0x7f))
|
32
|
+
VariableLengthQuantity.encode(List(0x3FFF)) should be(List(0xFF, 0x7F))
|
39
33
|
}
|
40
34
|
|
41
|
-
test("
|
35
|
+
test("smallest triple byte") {
|
42
36
|
pending
|
43
|
-
|
44
|
-
encoded should be (List(0x81, 0x80, 0x0))
|
37
|
+
VariableLengthQuantity.encode(List(0x4000)) should be(List(0x81, 0x80, 0x0))
|
45
38
|
}
|
46
39
|
|
47
|
-
test("
|
40
|
+
test("arbitrary triple byte") {
|
48
41
|
pending
|
49
|
-
|
50
|
-
|
42
|
+
VariableLengthQuantity.encode(List(0x100000)) should be(
|
43
|
+
List(0xC0, 0x80, 0x0))
|
51
44
|
}
|
52
45
|
|
53
|
-
test("
|
46
|
+
test("largest triple byte") {
|
54
47
|
pending
|
55
|
-
|
56
|
-
|
48
|
+
VariableLengthQuantity.encode(List(0x1FFFFF)) should be(
|
49
|
+
List(0xFF, 0xFF, 0x7F))
|
57
50
|
}
|
58
51
|
|
59
|
-
test("
|
52
|
+
test("smallest quadruple byte") {
|
60
53
|
pending
|
61
|
-
|
62
|
-
|
54
|
+
VariableLengthQuantity.encode(List(0x200000)) should be(
|
55
|
+
List(0x81, 0x80, 0x80, 0x0))
|
63
56
|
}
|
64
57
|
|
65
|
-
test("
|
58
|
+
test("arbitrary quadruple byte") {
|
66
59
|
pending
|
67
|
-
|
68
|
-
|
60
|
+
VariableLengthQuantity.encode(List(0x8000000)) should be(
|
61
|
+
List(0xC0, 0x80, 0x80, 0x0))
|
69
62
|
}
|
70
63
|
|
71
|
-
test("
|
64
|
+
test("largest quadruple byte") {
|
72
65
|
pending
|
73
|
-
|
74
|
-
|
66
|
+
VariableLengthQuantity.encode(List(0xFFFFFFF)) should be(
|
67
|
+
List(0xFF, 0xFF, 0xFF, 0x7F))
|
75
68
|
}
|
76
69
|
|
77
|
-
test("
|
70
|
+
test("smallest quintuple byte") {
|
78
71
|
pending
|
79
|
-
|
80
|
-
|
72
|
+
VariableLengthQuantity.encode(List(0x10000000)) should be(
|
73
|
+
List(0x81, 0x80, 0x80, 0x80, 0x0))
|
81
74
|
}
|
82
75
|
|
83
|
-
test("
|
76
|
+
test("arbitrary quintuple byte") {
|
84
77
|
pending
|
85
|
-
|
86
|
-
|
78
|
+
VariableLengthQuantity.encode(List(0xFF000000)) should be(
|
79
|
+
List(0x8F, 0xF8, 0x80, 0x80, 0x0))
|
87
80
|
}
|
88
81
|
|
89
|
-
test("
|
82
|
+
test("maximum 32-bit integer input") {
|
90
83
|
pending
|
91
|
-
|
92
|
-
|
84
|
+
VariableLengthQuantity.encode(List(0xFFFFFFFF)) should be(
|
85
|
+
List(0x8F, 0xFF, 0xFF, 0xFF, 0x7F))
|
93
86
|
}
|
94
87
|
|
95
|
-
test("
|
88
|
+
test("two single-byte values") {
|
96
89
|
pending
|
97
|
-
|
98
|
-
encoded should be (List(0x40, 0x7f))
|
90
|
+
VariableLengthQuantity.encode(List(0x40, 0x7F)) should be(List(0x40, 0x7F))
|
99
91
|
}
|
100
92
|
|
101
|
-
test("
|
93
|
+
test("two multi-byte values") {
|
102
94
|
pending
|
103
|
-
|
104
|
-
|
95
|
+
VariableLengthQuantity.encode(List(0x4000, 0x123456)) should be(
|
96
|
+
List(0x81, 0x80, 0x0, 0xC8, 0xE8, 0x56))
|
105
97
|
}
|
106
98
|
|
107
|
-
test("
|
99
|
+
test("many multi-byte values") {
|
108
100
|
pending
|
109
|
-
|
110
|
-
|
101
|
+
VariableLengthQuantity.encode(
|
102
|
+
List(0x2000, 0x123456, 0xFFFFFFF, 0x0, 0x3FFF, 0x4000)) should be(
|
103
|
+
List(0xC0, 0x0, 0xC8, 0xE8, 0x56, 0xFF, 0xFF, 0xFF, 0x7F, 0x0, 0xFF, 0x7F,
|
104
|
+
0x81, 0x80, 0x0))
|
111
105
|
}
|
112
106
|
|
113
|
-
|
114
|
-
test("decode: one byte") {
|
107
|
+
test("one byte") {
|
115
108
|
pending
|
116
|
-
|
117
|
-
decoded should be (Right(List(0x7f)))
|
109
|
+
VariableLengthQuantity.decode(List(0x7F)) should be(Right(List(0x7F)))
|
118
110
|
}
|
119
111
|
|
120
|
-
test("
|
112
|
+
test("two bytes") {
|
121
113
|
pending
|
122
|
-
|
123
|
-
|
114
|
+
VariableLengthQuantity.decode(List(0xC0, 0x0)) should be(
|
115
|
+
Right(List(0x2000)))
|
124
116
|
}
|
125
117
|
|
126
|
-
test("
|
118
|
+
test("three bytes") {
|
127
119
|
pending
|
128
|
-
|
129
|
-
|
120
|
+
VariableLengthQuantity.decode(List(0xFF, 0xFF, 0x7F)) should be(
|
121
|
+
Right(List(0x1FFFFF)))
|
130
122
|
}
|
131
123
|
|
132
|
-
test("
|
124
|
+
test("four bytes") {
|
133
125
|
pending
|
134
|
-
|
135
|
-
|
126
|
+
VariableLengthQuantity.decode(List(0x81, 0x80, 0x80, 0x0)) should be(
|
127
|
+
Right(List(0x200000)))
|
136
128
|
}
|
137
129
|
|
138
|
-
test("
|
130
|
+
test("maximum 32-bit integer") {
|
139
131
|
pending
|
140
|
-
|
141
|
-
|
132
|
+
VariableLengthQuantity.decode(List(0x8F, 0xFF, 0xFF, 0xFF, 0x7F)) should be(
|
133
|
+
Right(List(0xFFFFFFFF)))
|
142
134
|
}
|
143
135
|
|
144
|
-
test("
|
136
|
+
test("incomplete sequence causes error") {
|
145
137
|
pending
|
146
|
-
|
147
|
-
decoded.isLeft should be (true)
|
138
|
+
VariableLengthQuantity.decode(List(0xFF)).isLeft should be(true)
|
148
139
|
}
|
149
140
|
|
150
|
-
test("
|
141
|
+
test("incomplete sequence causes error, even if value is zero") {
|
151
142
|
pending
|
152
|
-
|
153
|
-
decoded.isLeft should be (true)
|
143
|
+
VariableLengthQuantity.decode(List(0x80)).isLeft should be(true)
|
154
144
|
}
|
155
145
|
|
156
|
-
test("
|
146
|
+
test("multiple values") {
|
157
147
|
pending
|
158
|
-
|
159
|
-
|
148
|
+
VariableLengthQuantity.decode(
|
149
|
+
List(0xC0, 0x0, 0xC8, 0xE8, 0x56, 0xFF, 0xFF, 0xFF, 0x7F, 0x0, 0xFF, 0x7F,
|
150
|
+
0x81, 0x80, 0x0)) should be(
|
151
|
+
Right(List(0x2000, 0x123456, 0xFFFFFFF, 0x0, 0x3FFF, 0x4000)))
|
160
152
|
}
|
161
|
-
|
162
153
|
}
|