trackler 2.0.3.2 → 2.0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/c/config.json +10 -0
- data/tracks/c/exercises/robot-simulator/makefile +16 -0
- data/tracks/c/exercises/robot-simulator/src/example.c +74 -0
- data/tracks/c/exercises/robot-simulator/src/robot_simulator.h +41 -0
- data/tracks/c/exercises/robot-simulator/test/test_robot_simulator.c +165 -0
- data/tracks/c/exercises/robot-simulator/test/vendor/unity.c +1300 -0
- data/tracks/c/exercises/robot-simulator/test/vendor/unity.h +274 -0
- data/tracks/c/exercises/robot-simulator/test/vendor/unity_internals.h +701 -0
- data/tracks/ecmascript/exercises/rna-transcription/example.js +9 -2
- data/tracks/ecmascript/exercises/rna-transcription/rna-transcription.spec.js +18 -0
- data/tracks/go/exercises/hello-world/example.go +4 -2
- data/tracks/go/exercises/hello-world/hello_test.go +4 -4
- data/tracks/go/exercises/hello-world/hello_world.go +6 -6
- data/tracks/groovy/config.json +5 -0
- data/tracks/groovy/exercises/phone-number/Example.groovy +20 -0
- data/tracks/groovy/exercises/phone-number/PhoneNumberSpec.groovy +75 -0
- data/tracks/haskell/exercises/difference-of-squares/test/Tests.hs +2 -0
- data/tracks/java/config.json +13 -1
- data/tracks/java/exercises/all-your-base/build.gradle +17 -0
- data/tracks/java/exercises/all-your-base/src/example/java/BaseConverter.java +80 -0
- data/tracks/java/exercises/all-your-base/src/main/java/BaseConverter.java +5 -0
- data/tracks/java/exercises/all-your-base/src/test/java/BaseConverterTest.java +256 -0
- data/tracks/java/exercises/binary-search/build.gradle +17 -0
- data/tracks/java/exercises/binary-search/src/example/java/BinarySearch.java +40 -0
- data/tracks/java/exercises/binary-search/src/main/java/.keep +0 -0
- data/tracks/java/exercises/binary-search/src/main/java/BinarySearch.java +4 -0
- data/tracks/java/exercises/binary-search/src/test/java/.keep +0 -0
- data/tracks/java/exercises/binary-search/src/test/java/BinarySearchTest.java +136 -0
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/lua/config.json +16 -0
- data/tracks/lua/exercises/say/example.lua +92 -0
- data/tracks/lua/exercises/say/say_spec.lua +105 -0
- data/tracks/lua/exercises/secret-handshake/example.lua +17 -0
- data/tracks/lua/exercises/secret-handshake/secret-handshake_spec.lua +38 -0
- data/tracks/ocaml/config.json +10 -1
- data/tracks/ocaml/exercises/bracket-push/.merlin +3 -0
- data/tracks/ocaml/exercises/bracket-push/Makefile +11 -0
- data/tracks/ocaml/exercises/bracket-push/bracket_push.mli +3 -0
- data/tracks/ocaml/exercises/bracket-push/example.ml +40 -0
- data/tracks/ocaml/exercises/bracket-push/test.ml +38 -0
- data/tracks/ocaml/exercises/leap/test.ml +7 -7
- data/tracks/ocaml/tools/test-generator/Makefile +2 -2
- data/tracks/ocaml/tools/test-generator/interfaces/codegen.mli +2 -2
- data/tracks/ocaml/tools/test-generator/interfaces/{test_generator.mli → controller.mli} +0 -0
- data/tracks/ocaml/tools/test-generator/interfaces/parser.mli +7 -1
- data/tracks/ocaml/tools/test-generator/interfaces/special_cases.mli +2 -2
- data/tracks/ocaml/tools/test-generator/interfaces/utils.mli +4 -0
- data/tracks/ocaml/tools/test-generator/src/codegen.ml +9 -5
- data/tracks/ocaml/tools/test-generator/src/{test_generator.ml → controller.ml} +24 -15
- data/tracks/ocaml/tools/test-generator/src/model.ml +6 -0
- data/tracks/ocaml/tools/test-generator/src/parser.ml +34 -7
- data/tracks/ocaml/tools/test-generator/src/special_cases.ml +11 -4
- data/tracks/ocaml/tools/test-generator/src/template.ml +49 -6
- data/tracks/ocaml/tools/test-generator/src/test_gen.ml +1 -1
- data/tracks/ocaml/tools/test-generator/src/utils.ml +6 -0
- data/tracks/ocaml/tools/test-generator/templates/anagram/template.ml +2 -2
- data/tracks/ocaml/tools/test-generator/templates/bob/template.ml +2 -2
- data/tracks/ocaml/tools/test-generator/templates/bracket-push/template.ml +16 -0
- data/tracks/ocaml/tools/test-generator/templates/difference-of-squares/template.ml +19 -0
- data/tracks/ocaml/tools/test-generator/templates/hamming/template.ml +2 -2
- data/tracks/ocaml/tools/test-generator/templates/hello-world/template.ml +2 -2
- data/tracks/ocaml/tools/test-generator/templates/leap/template.ml +2 -2
- data/tracks/ocaml/tools/test-generator/templates/raindrops/template.ml +2 -2
- data/tracks/ocaml/tools/test-generator/templates/say/template.ml +3 -3
- data/tracks/ocaml/tools/test-generator/templates/word-count/template.ml +2 -2
- data/tracks/ocaml/tools/test-generator/test/all_tests.ml +3 -1
- data/tracks/ocaml/tools/test-generator/test/codegen_test.ml +7 -7
- data/tracks/ocaml/tools/test-generator/test/difference_of_squares.json +67 -0
- data/tracks/ocaml/tools/test-generator/test/hello_world.json +23 -0
- data/tracks/ocaml/tools/test-generator/test/parser_test.ml +30 -12
- data/tracks/ocaml/tools/test-generator/test/sample-suite-template.txt +16 -0
- data/tracks/ocaml/tools/test-generator/test/sample_template.txt +2 -2
- data/tracks/ocaml/tools/test-generator/test/special_cases_test.ml +1 -1
- data/tracks/ocaml/tools/test-generator/test/template_test.ml +40 -6
- data/tracks/perl6/.travis.yml +3 -0
- data/tracks/perl6/docs/RESOURCES.md +1 -1
- data/tracks/perl6/exercises/accumulate/accumulate.t +3 -7
- data/tracks/perl6/exercises/anagram/anagram.t +3 -7
- data/tracks/perl6/exercises/binary/binary.t +3 -7
- data/tracks/perl6/exercises/bob/bob.t +4 -8
- data/tracks/perl6/exercises/grains/grains.t +3 -7
- data/tracks/perl6/exercises/leap/leap.t +3 -7
- data/tracks/perl6/exercises/rna-transcription/rna_transcription.t +4 -8
- data/tracks/perl6/exercises/robot-name/robot.t +4 -8
- data/tracks/perl6/exercises/scrabble-score/scrabble_score.t +3 -7
- data/tracks/perl6/exercises/word-count/word_count.t +3 -8
- data/tracks/r/config.json +10 -0
- data/tracks/r/docs/ABOUT.md +14 -0
- data/tracks/r/exercises/difference-of-squares/difference-of-squares.R +5 -0
- data/tracks/r/exercises/difference-of-squares/example.R +6 -0
- data/tracks/r/exercises/difference-of-squares/test_difference-of-squares.R +23 -0
- data/tracks/r/exercises/hamming/example.R +8 -0
- data/tracks/r/exercises/hamming/hamming.R +4 -0
- data/tracks/r/exercises/hamming/test_hamming.R +87 -0
- data/tracks/ruby/exercises/binary/.version +1 -1
- data/tracks/ruby/exercises/binary/binary_test.rb +17 -19
- data/tracks/ruby/exercises/binary/example.rb +13 -13
- data/tracks/ruby/exercises/isogram/.version +1 -1
- data/tracks/ruby/exercises/isogram/example.rb +1 -1
- data/tracks/ruby/exercises/isogram/isogram_test.rb +16 -30
- data/tracks/ruby/lib/binary_cases.rb +2 -3
- data/tracks/ruby/lib/isogram_cases.rb +1 -5
- data/tracks/scala/exercises/phone-number/HINTS.md +9 -0
- metadata +45 -4
@@ -7,7 +7,14 @@ const DNA_TO_RNA = {
|
|
7
7
|
|
8
8
|
export default class Transcriptor {
|
9
9
|
toRna(dna) {
|
10
|
-
|
10
|
+
let rna = dna.replace(/./g, nucleotide => DNA_TO_RNA[nucleotide])
|
11
|
+
|
12
|
+
if (rna.length !== dna.length) {
|
13
|
+
// invalid characters in the strand
|
14
|
+
throw new Error('Invalid input DNA.');
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
return rna;
|
18
|
+
}
|
11
19
|
}
|
12
20
|
}
|
13
|
-
|
@@ -24,4 +24,22 @@ describe('Transcriptor', () => {
|
|
24
24
|
.toEqual('UGCACCAGAAUU');
|
25
25
|
});
|
26
26
|
|
27
|
+
xit('correctly handles invalid input', () => {
|
28
|
+
expect(() => transcriptor.toRna('U')).toThrow(
|
29
|
+
new Error('Invalid input DNA.')
|
30
|
+
);
|
31
|
+
});
|
32
|
+
|
33
|
+
xit('correctly handles completely invalid input', () => {
|
34
|
+
expect(() => transcriptor.toRna('XXX')).toThrow(
|
35
|
+
new Error('Invalid input DNA.')
|
36
|
+
);
|
37
|
+
});
|
38
|
+
|
39
|
+
xit('correctly handles partially invalid input', () => {
|
40
|
+
expect(() => transcriptor.toRna('ACGTXXXCTTAA')).toThrow(
|
41
|
+
new Error('Invalid input DNA.')
|
42
|
+
);
|
43
|
+
});
|
44
|
+
|
27
45
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
package
|
1
|
+
package greeting
|
2
2
|
|
3
3
|
import "testing"
|
4
4
|
|
@@ -7,7 +7,7 @@ import "testing"
|
|
7
7
|
// Also define a testVersion with a value that matches
|
8
8
|
// the targetTestVersion here.
|
9
9
|
|
10
|
-
const targetTestVersion =
|
10
|
+
const targetTestVersion = 3
|
11
11
|
|
12
12
|
func TestHelloWorld(t *testing.T) {
|
13
13
|
tests := []struct {
|
@@ -15,10 +15,10 @@ func TestHelloWorld(t *testing.T) {
|
|
15
15
|
}{
|
16
16
|
{"", "Hello, World!"},
|
17
17
|
{"Gopher", "Hello, Gopher!"},
|
18
|
+
{"ゴーファー", "Hello, ゴーファー!"},
|
18
19
|
}
|
19
20
|
for _, test := range tests {
|
20
|
-
observed := HelloWorld(test.name)
|
21
|
-
if observed != test.expected {
|
21
|
+
if observed := HelloWorld(test.name); observed != test.expected {
|
22
22
|
t.Fatalf("HelloWorld(%s) = %v, want %v", test.name, observed, test.expected)
|
23
23
|
}
|
24
24
|
}
|
@@ -1,23 +1,23 @@
|
|
1
1
|
// This is a "stub" file. It's a little start on your solution.
|
2
2
|
// It's not a complete solution though; you have to write some code.
|
3
3
|
|
4
|
-
//
|
5
|
-
//
|
6
|
-
package
|
4
|
+
// Package greeting should have a package comment that summarizes what it's about.
|
5
|
+
// https://golang.org/doc/effective_go.html#commentary
|
6
|
+
package greeting
|
7
7
|
|
8
8
|
// testVersion identifies the version of the test program that you are
|
9
9
|
// writing your code to. If the test program changes in the future --
|
10
10
|
// after you have posted this code to the Exercism site -- nitpickers
|
11
11
|
// will see that your code can't necessarily be expected to pass the
|
12
12
|
// current test suite because it was written to an earlier test version.
|
13
|
-
const testVersion =
|
13
|
+
const testVersion = 3
|
14
14
|
|
15
|
-
//
|
16
|
-
// (But delete all these instructional comments!)
|
15
|
+
// HelloWorld needs a comment documenting it as package does.
|
17
16
|
func HelloWorld(string) string {
|
18
17
|
// Write some code here to pass the test suite.
|
19
18
|
|
20
19
|
// When you have a working solution, REMOVE ALL THE STOCK COMMENTS.
|
21
20
|
// They're here to help you get started but they only clutter a finished solution.
|
22
21
|
// If you leave them in, nitpickers will protest!
|
22
|
+
return ""
|
23
23
|
}
|
data/tracks/groovy/config.json
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
class PhoneNumber {
|
2
|
+
|
3
|
+
private static def REGEX = ~/^1?[\s\.\-\(]*(\d{3})[\s\.\-\)]*\s?(\d{3})[\s\.\-]*(\d{4})$/
|
4
|
+
|
5
|
+
String areaCode = '000', exchange = '000', subscriber = '0000'
|
6
|
+
|
7
|
+
public PhoneNumber(String input) {
|
8
|
+
def matcher = REGEX.matcher(input)
|
9
|
+
if ( matcher.matches() ) {
|
10
|
+
areaCode = "${matcher.group(1)}"
|
11
|
+
exchange = "${matcher.group(2)}"
|
12
|
+
subscriber = "${matcher.group(3)}"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
String getNumber() { "${areaCode}${exchange}${subscriber}" }
|
17
|
+
|
18
|
+
String toString() { "(${areaCode}) ${exchange}-${subscriber}" }
|
19
|
+
|
20
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
@Grab('org.spockframework:spock-core:1.0-groovy-2.4')
|
2
|
+
import spock.lang.*
|
3
|
+
|
4
|
+
class PhoneNumberSpec extends Specification {
|
5
|
+
|
6
|
+
def 'a phone number is valid'() {
|
7
|
+
expect: new PhoneNumber('(123) 456-7890').number == '1234567890'
|
8
|
+
}
|
9
|
+
|
10
|
+
@Ignore
|
11
|
+
def 'a different phone number is valid'() {
|
12
|
+
expect: new PhoneNumber('(987) 654-3210').number == '9876543210'
|
13
|
+
}
|
14
|
+
|
15
|
+
@Ignore
|
16
|
+
def 'a phone nubmer separated by dots is valid'() {
|
17
|
+
expect: new PhoneNumber('456.123.7890').number == '4561237890'
|
18
|
+
}
|
19
|
+
|
20
|
+
@Ignore
|
21
|
+
def 'a letter-containing phone number is invalid'() {
|
22
|
+
expect: new PhoneNumber('123-abc-1234').number == '0000000000'
|
23
|
+
}
|
24
|
+
|
25
|
+
@Ignore
|
26
|
+
def 'a 9-digit number is invalid'() {
|
27
|
+
expect: new PhoneNumber('123456789').number == '0000000000'
|
28
|
+
}
|
29
|
+
|
30
|
+
@Ignore
|
31
|
+
def 'an 11-digit number starting with a 1 is valid'() {
|
32
|
+
expect: new PhoneNumber('19876543210').number == '9876543210'
|
33
|
+
}
|
34
|
+
|
35
|
+
@Ignore
|
36
|
+
def 'a 10-digit number, with an area code starting with 1, is valid'() {
|
37
|
+
expect: new PhoneNumber('1234567890').number == '1234567890'
|
38
|
+
}
|
39
|
+
|
40
|
+
@Ignore
|
41
|
+
def 'an 11-digit number, not beginning with a 1, is invalid'(){
|
42
|
+
expect: new PhoneNumber('21234567890').number == '0000000000'
|
43
|
+
}
|
44
|
+
|
45
|
+
@Ignore
|
46
|
+
def 'a 12-digit number, even one beginning with a 1, is invalid'(){
|
47
|
+
expect: new PhoneNumber('112345678901').number == '0000000000'
|
48
|
+
}
|
49
|
+
|
50
|
+
@Ignore
|
51
|
+
def 'a 10-digit number containing letters is inavlid'() {
|
52
|
+
expect: new PhoneNumber('1a2a3a4a5a6a7a8a9a0a').number == '0000000000'
|
53
|
+
}
|
54
|
+
|
55
|
+
@Ignore
|
56
|
+
def 'can extract area code from a phone number'() {
|
57
|
+
expect: new PhoneNumber('1234567890').areaCode == '123'
|
58
|
+
}
|
59
|
+
|
60
|
+
@Ignore
|
61
|
+
def 'can extract an area code from a different phone number'() {
|
62
|
+
expect: new PhoneNumber('9876543210').areaCode == '987'
|
63
|
+
}
|
64
|
+
|
65
|
+
@Ignore
|
66
|
+
def 'can pretty print a phone number'() {
|
67
|
+
expect: new PhoneNumber('5551234567').toString() == '(555) 123-4567'
|
68
|
+
}
|
69
|
+
|
70
|
+
@Ignore
|
71
|
+
def 'can pretty print a full U.S. phone number'() {
|
72
|
+
expect: new PhoneNumber('11234567890').toString() == '(123) 456-7890'
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
@@ -64,7 +64,9 @@ specs = describe "differenceOfSquares" $ do
|
|
64
64
|
difference (12 :: Integer)
|
65
65
|
`shouldBe` (5434 :: Integer)
|
66
66
|
|
67
|
+
{-
|
67
68
|
describe "huge difference" $
|
68
69
|
it "difference (1234567890 :: Integer)" $
|
69
70
|
difference (1234567890 :: Integer)
|
70
71
|
`shouldBe` (580764307309260838625720836817589660 :: Integer)
|
72
|
+
-}
|
data/tracks/java/config.json
CHANGED
@@ -52,7 +52,9 @@
|
|
52
52
|
"robot-simulator",
|
53
53
|
"bracket-push",
|
54
54
|
"pythagorean-triplet",
|
55
|
-
"binary-search-tree"
|
55
|
+
"binary-search-tree",
|
56
|
+
"binary-search",
|
57
|
+
"all-your-base"
|
56
58
|
],
|
57
59
|
"exercises": [
|
58
60
|
{
|
@@ -299,6 +301,16 @@
|
|
299
301
|
"slug": "binary-search-tree",
|
300
302
|
"difficulty": 1,
|
301
303
|
"topics": []
|
304
|
+
},
|
305
|
+
{
|
306
|
+
"slug": "binary-search",
|
307
|
+
"difficulty": 1,
|
308
|
+
"topics": []
|
309
|
+
},
|
310
|
+
{
|
311
|
+
"slug": "all-your-base",
|
312
|
+
"difficulty": 1,
|
313
|
+
"topics": []
|
302
314
|
}
|
303
315
|
],
|
304
316
|
"deprecated": [
|
@@ -0,0 +1,17 @@
|
|
1
|
+
apply plugin: "java"
|
2
|
+
apply plugin: "eclipse"
|
3
|
+
apply plugin: "idea"
|
4
|
+
|
5
|
+
repositories {
|
6
|
+
mavenCentral()
|
7
|
+
}
|
8
|
+
|
9
|
+
dependencies {
|
10
|
+
testCompile "junit:junit:4.12"
|
11
|
+
}
|
12
|
+
test {
|
13
|
+
testLogging {
|
14
|
+
exceptionFormat = 'full'
|
15
|
+
events = ["passed", "failed", "skipped"]
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import java.util.Arrays;
|
2
|
+
|
3
|
+
final class BaseConverter {
|
4
|
+
|
5
|
+
private static final int MINIMUM_VALID_BASE = 2;
|
6
|
+
|
7
|
+
private static final String INVALID_BASE_ERROR_MESSAGE = "Bases must be at least 2.";
|
8
|
+
|
9
|
+
private final int numeral;
|
10
|
+
|
11
|
+
BaseConverter(final int originalBase, final int[] originalDigits) {
|
12
|
+
validateInputs(originalBase, originalDigits);
|
13
|
+
this.numeral = computeNumeral(originalBase, originalDigits);
|
14
|
+
}
|
15
|
+
|
16
|
+
int[] convertToBase(final int newBase) {
|
17
|
+
if (newBase < MINIMUM_VALID_BASE) {
|
18
|
+
throw new IllegalArgumentException(INVALID_BASE_ERROR_MESSAGE);
|
19
|
+
}
|
20
|
+
|
21
|
+
final int largestExponent = computeLargestExponentForBase(newBase);
|
22
|
+
final int[] result = new int[largestExponent + 1];
|
23
|
+
int remainder = numeral;
|
24
|
+
|
25
|
+
for (int currentExponent = largestExponent; currentExponent >= 0; currentExponent--) {
|
26
|
+
final int coefficient = (int) Math.floor(remainder / Math.pow(newBase, currentExponent));
|
27
|
+
|
28
|
+
result[largestExponent - currentExponent] = coefficient;
|
29
|
+
|
30
|
+
remainder -= coefficient * Math.pow(newBase, currentExponent);
|
31
|
+
}
|
32
|
+
|
33
|
+
return result;
|
34
|
+
}
|
35
|
+
|
36
|
+
private void validateInputs(final int originalBase, final int[] originalDigits) {
|
37
|
+
if (originalBase < MINIMUM_VALID_BASE) {
|
38
|
+
throw new IllegalArgumentException(INVALID_BASE_ERROR_MESSAGE);
|
39
|
+
}
|
40
|
+
|
41
|
+
if (originalDigits.length == 0) {
|
42
|
+
throw new IllegalArgumentException("You must supply at least one digit.");
|
43
|
+
}
|
44
|
+
|
45
|
+
if (originalDigits.length > 1 && originalDigits[0] == 0) {
|
46
|
+
throw new IllegalArgumentException("Digits may not contain leading zeros.");
|
47
|
+
}
|
48
|
+
|
49
|
+
if (Arrays.stream(originalDigits).min().getAsInt() < 0) {
|
50
|
+
throw new IllegalArgumentException("Digits may not be negative.");
|
51
|
+
}
|
52
|
+
|
53
|
+
if (Arrays.stream(originalDigits).max().getAsInt() >= originalBase) {
|
54
|
+
throw new IllegalArgumentException("All digits must be strictly less than the base.");
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
private int computeNumeral(final int originalBase, final int[] originalDigits) {
|
59
|
+
int result = 0;
|
60
|
+
|
61
|
+
final int largestExponent = originalDigits.length - 1;
|
62
|
+
|
63
|
+
for (int currentExponent = largestExponent; currentExponent >= 0; currentExponent--) {
|
64
|
+
result += originalDigits[largestExponent - currentExponent] * Math.pow(originalBase, currentExponent);
|
65
|
+
}
|
66
|
+
|
67
|
+
return result;
|
68
|
+
}
|
69
|
+
|
70
|
+
private int computeLargestExponentForBase(final int newBase) {
|
71
|
+
int result = 0;
|
72
|
+
|
73
|
+
while (Math.pow(newBase, result + 1) < numeral) {
|
74
|
+
result += 1;
|
75
|
+
}
|
76
|
+
|
77
|
+
return result;
|
78
|
+
}
|
79
|
+
|
80
|
+
}
|
@@ -0,0 +1,256 @@
|
|
1
|
+
import org.junit.Rule;
|
2
|
+
import org.junit.Test;
|
3
|
+
import org.junit.rules.ExpectedException;
|
4
|
+
|
5
|
+
import java.util.Arrays;
|
6
|
+
|
7
|
+
import static org.junit.Assert.assertArrayEquals;
|
8
|
+
|
9
|
+
public final class BaseConverterTest {
|
10
|
+
|
11
|
+
/*
|
12
|
+
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
|
13
|
+
* ExpectedExceptions in particular.
|
14
|
+
*/
|
15
|
+
@Rule
|
16
|
+
public ExpectedException expectedException = ExpectedException.none();
|
17
|
+
|
18
|
+
@Test
|
19
|
+
public void testSingleBitOneToDecimal() {
|
20
|
+
final BaseConverter baseConverter = new BaseConverter(2, new int[]{1});
|
21
|
+
|
22
|
+
final int[] expectedDigits = new int[]{1};
|
23
|
+
final int[] actualDigits = baseConverter.convertToBase(10);
|
24
|
+
|
25
|
+
assertArrayEquals(
|
26
|
+
String.format(
|
27
|
+
"Expected digits: %s but found digits: %s",
|
28
|
+
Arrays.toString(expectedDigits),
|
29
|
+
Arrays.toString(actualDigits)),
|
30
|
+
expectedDigits,
|
31
|
+
actualDigits);
|
32
|
+
}
|
33
|
+
|
34
|
+
@Test
|
35
|
+
public void testBinaryToSingleDecimal() {
|
36
|
+
final BaseConverter baseConverter = new BaseConverter(2, new int[]{1, 0, 1});
|
37
|
+
|
38
|
+
final int[] expectedDigits = new int[]{5};
|
39
|
+
final int[] actualDigits = baseConverter.convertToBase(10);
|
40
|
+
|
41
|
+
assertArrayEquals(
|
42
|
+
String.format(
|
43
|
+
"Expected digits: %s but found digits: %s",
|
44
|
+
Arrays.toString(expectedDigits),
|
45
|
+
Arrays.toString(actualDigits)),
|
46
|
+
expectedDigits,
|
47
|
+
actualDigits);
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void testSingleDecimalToBinary() {
|
52
|
+
final BaseConverter baseConverter = new BaseConverter(10, new int[]{5});
|
53
|
+
|
54
|
+
final int[] expectedDigits = new int[]{1, 0, 1};
|
55
|
+
final int[] actualDigits = baseConverter.convertToBase(2);
|
56
|
+
|
57
|
+
assertArrayEquals(
|
58
|
+
String.format(
|
59
|
+
"Expected digits: %s but found digits: %s",
|
60
|
+
Arrays.toString(expectedDigits),
|
61
|
+
Arrays.toString(actualDigits)),
|
62
|
+
expectedDigits,
|
63
|
+
actualDigits);
|
64
|
+
}
|
65
|
+
|
66
|
+
@Test
|
67
|
+
public void testBinaryToMultipleDecimal() {
|
68
|
+
final BaseConverter baseConverter = new BaseConverter(2, new int[]{1, 0, 1, 0, 1, 0});
|
69
|
+
|
70
|
+
final int[] expectedDigits = new int[]{4, 2};
|
71
|
+
final int[] actualDigits = baseConverter.convertToBase(10);
|
72
|
+
|
73
|
+
assertArrayEquals(
|
74
|
+
String.format(
|
75
|
+
"Expected digits: %s but found digits: %s",
|
76
|
+
Arrays.toString(expectedDigits),
|
77
|
+
Arrays.toString(actualDigits)),
|
78
|
+
expectedDigits,
|
79
|
+
actualDigits);
|
80
|
+
}
|
81
|
+
|
82
|
+
@Test
|
83
|
+
public void testDecimalToBinary() {
|
84
|
+
final BaseConverter baseConverter = new BaseConverter(10, new int[]{4, 2});
|
85
|
+
|
86
|
+
final int[] expectedDigits = new int[]{1, 0, 1, 0, 1, 0};
|
87
|
+
final int[] actualDigits = baseConverter.convertToBase(2);
|
88
|
+
|
89
|
+
assertArrayEquals(
|
90
|
+
String.format(
|
91
|
+
"Expected digits: %s but found digits: %s",
|
92
|
+
Arrays.toString(expectedDigits),
|
93
|
+
Arrays.toString(actualDigits)),
|
94
|
+
expectedDigits,
|
95
|
+
actualDigits);
|
96
|
+
}
|
97
|
+
|
98
|
+
@Test
|
99
|
+
public void testTrinaryToHexadecimal() {
|
100
|
+
final BaseConverter baseConverter = new BaseConverter(3, new int[]{1, 1, 2, 0});
|
101
|
+
|
102
|
+
final int[] expectedDigits = new int[]{2, 10};
|
103
|
+
final int[] actualDigits = baseConverter.convertToBase(16);
|
104
|
+
|
105
|
+
assertArrayEquals(
|
106
|
+
String.format(
|
107
|
+
"Expected digits: %s but found digits: %s",
|
108
|
+
Arrays.toString(expectedDigits),
|
109
|
+
Arrays.toString(actualDigits)),
|
110
|
+
expectedDigits,
|
111
|
+
actualDigits);
|
112
|
+
}
|
113
|
+
|
114
|
+
@Test
|
115
|
+
public void testHexadecimalToTrinary() {
|
116
|
+
final BaseConverter baseConverter = new BaseConverter(16, new int[]{2, 10});
|
117
|
+
|
118
|
+
final int[] expectedDigits = new int[]{1, 1, 2, 0};
|
119
|
+
final int[] actualDigits = baseConverter.convertToBase(3);
|
120
|
+
|
121
|
+
assertArrayEquals(
|
122
|
+
String.format(
|
123
|
+
"Expected digits: %s but found digits: %s",
|
124
|
+
Arrays.toString(expectedDigits),
|
125
|
+
Arrays.toString(actualDigits)),
|
126
|
+
expectedDigits,
|
127
|
+
actualDigits);
|
128
|
+
}
|
129
|
+
|
130
|
+
@Test
|
131
|
+
public void test15BitInteger() {
|
132
|
+
final BaseConverter baseConverter = new BaseConverter(97, new int[]{3, 46, 60});
|
133
|
+
|
134
|
+
final int[] expectedDigits = new int[]{6, 10, 45};
|
135
|
+
final int[] actualDigits = baseConverter.convertToBase(73);
|
136
|
+
|
137
|
+
assertArrayEquals(
|
138
|
+
String.format(
|
139
|
+
"Expected digits: %s but found digits: %s",
|
140
|
+
Arrays.toString(expectedDigits),
|
141
|
+
Arrays.toString(actualDigits)),
|
142
|
+
expectedDigits,
|
143
|
+
actualDigits);
|
144
|
+
}
|
145
|
+
|
146
|
+
@Test
|
147
|
+
public void testEmptyDigits() {
|
148
|
+
expectedException.expect(IllegalArgumentException.class);
|
149
|
+
expectedException.expectMessage("You must supply at least one digit.");
|
150
|
+
|
151
|
+
new BaseConverter(2, new int[]{});
|
152
|
+
}
|
153
|
+
|
154
|
+
@Test
|
155
|
+
public void testSingleZero() {
|
156
|
+
final BaseConverter baseConverter = new BaseConverter(10, new int[]{0});
|
157
|
+
|
158
|
+
final int[] expectedDigits = new int[]{0};
|
159
|
+
final int[] actualDigits = baseConverter.convertToBase(2);
|
160
|
+
|
161
|
+
assertArrayEquals(
|
162
|
+
String.format(
|
163
|
+
"Expected digits: %s but found digits: %s",
|
164
|
+
Arrays.toString(expectedDigits),
|
165
|
+
Arrays.toString(actualDigits)),
|
166
|
+
expectedDigits,
|
167
|
+
actualDigits);
|
168
|
+
}
|
169
|
+
|
170
|
+
@Test
|
171
|
+
public void testMultipleZeros() {
|
172
|
+
expectedException.expect(IllegalArgumentException.class);
|
173
|
+
expectedException.expectMessage("Digits may not contain leading zeros.");
|
174
|
+
|
175
|
+
new BaseConverter(10, new int[]{0, 0, 0});
|
176
|
+
}
|
177
|
+
|
178
|
+
@Test
|
179
|
+
public void testLeadingZeros() {
|
180
|
+
expectedException.expect(IllegalArgumentException.class);
|
181
|
+
expectedException.expectMessage("Digits may not contain leading zeros.");
|
182
|
+
|
183
|
+
new BaseConverter(7, new int[]{0, 6, 0});
|
184
|
+
}
|
185
|
+
|
186
|
+
@Test
|
187
|
+
public void testNegativeDigit() {
|
188
|
+
expectedException.expect(IllegalArgumentException.class);
|
189
|
+
expectedException.expectMessage("Digits may not be negative.");
|
190
|
+
|
191
|
+
new BaseConverter(2, new int[]{1, -1, 1, 0, 1, 0});
|
192
|
+
}
|
193
|
+
|
194
|
+
@Test
|
195
|
+
public void testInvalidPositiveDigit() {
|
196
|
+
expectedException.expect(IllegalArgumentException.class);
|
197
|
+
expectedException.expectMessage("All digits must be strictly less than the base.");
|
198
|
+
|
199
|
+
new BaseConverter(2, new int[]{1, 2, 1, 0, 1, 0});
|
200
|
+
}
|
201
|
+
|
202
|
+
@Test
|
203
|
+
public void testFirstBaseIsOne() {
|
204
|
+
expectedException.expect(IllegalArgumentException.class);
|
205
|
+
expectedException.expectMessage("Bases must be at least 2.");
|
206
|
+
|
207
|
+
new BaseConverter(1, new int[]{});
|
208
|
+
}
|
209
|
+
|
210
|
+
@Test
|
211
|
+
public void testSecondBaseIsOne() {
|
212
|
+
final BaseConverter baseConverter = new BaseConverter(2, new int[]{1, 0, 1, 0, 1, 0});
|
213
|
+
|
214
|
+
expectedException.expect(IllegalArgumentException.class);
|
215
|
+
expectedException.expectMessage("Bases must be at least 2.");
|
216
|
+
|
217
|
+
baseConverter.convertToBase(1);
|
218
|
+
}
|
219
|
+
|
220
|
+
@Test
|
221
|
+
public void testFirstBaseIsZero() {
|
222
|
+
expectedException.expect(IllegalArgumentException.class);
|
223
|
+
expectedException.expectMessage("Bases must be at least 2.");
|
224
|
+
|
225
|
+
new BaseConverter(0, new int[]{});
|
226
|
+
}
|
227
|
+
|
228
|
+
@Test
|
229
|
+
public void testSecondBaseIsZero() {
|
230
|
+
final BaseConverter baseConverter = new BaseConverter(2, new int[]{1, 0, 1, 0, 1, 0});
|
231
|
+
|
232
|
+
expectedException.expect(IllegalArgumentException.class);
|
233
|
+
expectedException.expectMessage("Bases must be at least 2.");
|
234
|
+
|
235
|
+
baseConverter.convertToBase(0);
|
236
|
+
}
|
237
|
+
|
238
|
+
@Test
|
239
|
+
public void testFirstBaseIsNegative() {
|
240
|
+
expectedException.expect(IllegalArgumentException.class);
|
241
|
+
expectedException.expectMessage("Bases must be at least 2.");
|
242
|
+
|
243
|
+
new BaseConverter(-2, new int[]{});
|
244
|
+
}
|
245
|
+
|
246
|
+
@Test
|
247
|
+
public void testSecondBaseIsNegative() {
|
248
|
+
final BaseConverter baseConverter = new BaseConverter(2, new int[]{1});
|
249
|
+
|
250
|
+
expectedException.expect(IllegalArgumentException.class);
|
251
|
+
expectedException.expectMessage("Bases must be at least 2.");
|
252
|
+
|
253
|
+
baseConverter.convertToBase(-7);
|
254
|
+
}
|
255
|
+
|
256
|
+
}
|