Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
40db15f
add roman number conversion tests and logic
Sep 28, 2016
2e03922
besouro automatic message
Oct 5, 2016
c297211
besouro automatic message
Oct 5, 2016
47875c9
besouro automatic message
Oct 5, 2016
08ad22d
besouro automatic message
Oct 5, 2016
e3f6561
besouro automatic message
Oct 5, 2016
63ecd08
besouro automatic message
Oct 5, 2016
e9a7e8c
besouro automatic message
Oct 5, 2016
5498403
besouro automatic message
Oct 5, 2016
32507ca
besouro automatic message
Oct 5, 2016
78969df
besouro automatic message
Oct 5, 2016
63724d7
besouro automatic message
Oct 5, 2016
84c7fc3
besouro automatic message
Oct 5, 2016
964e21c
besouro automatic message
Oct 5, 2016
f4be38e
besouro automatic message
Oct 5, 2016
2a52be6
besouro automatic message
Oct 5, 2016
c615e2e
besouro automatic message
Oct 5, 2016
05db897
besouro automatic message
Oct 5, 2016
b5e1145
besouro automatic message
Oct 5, 2016
14c274c
besouro automatic message
Oct 5, 2016
0efbe03
besouro automatic message
Oct 5, 2016
a7b81ca
besouro automatic message
Oct 5, 2016
05c6ec3
besouro automatic message
Oct 5, 2016
9eb078b
besouro automatic message
Oct 5, 2016
52d56b1
besouro automatic message
Oct 5, 2016
3752e9e
besouro automatic message
Oct 5, 2016
b6aec38
besouro automatic message
Oct 5, 2016
9ad0a7e
besouro automatic message
Oct 5, 2016
93f9133
besouro automatic message
Oct 5, 2016
e44105b
besouro automatic message
Oct 5, 2016
eb9d5eb
besouro automatic message
Oct 5, 2016
4e5de31
besouro automatic message
Oct 5, 2016
7a4bc27
besouro automatic message
Oct 5, 2016
3bd0ea8
besouro automatic message
Oct 5, 2016
32ded56
besouro automatic message
Oct 5, 2016
12dd086
besouro automatic message
Oct 5, 2016
8ce62c0
besouro automatic message
Oct 5, 2016
c5bd196
besouro automatic message
Oct 5, 2016
27a4ffd
besouro automatic message
Oct 5, 2016
41a000f
besouro automatic message
Oct 5, 2016
cc4d41f
besouro automatic message
Oct 5, 2016
b7afcf2
besouro automatic message
Oct 5, 2016
af9f3e5
besouro automatic message
Oct 5, 2016
895696d
besouro automatic message
Oct 5, 2016
d9ea720
besouro automatic message
Oct 5, 2016
cbb549c
besouro automatic message
Oct 5, 2016
f83e576
besouro automatic message
Oct 5, 2016
958b4c9
besouro automatic message
Oct 5, 2016
8bce634
besouro automatic message
Oct 5, 2016
11b5dbb
besouro automatic message
Oct 5, 2016
2145f3e
besouro automatic message
Oct 5, 2016
e5623a3
besouro automatic message
Oct 5, 2016
c8caa53
besouro automatic message
Oct 5, 2016
74ef762
besouro automatic message
Oct 5, 2016
b76a32e
besouro automatic message
Oct 5, 2016
2552d2e
besouro automatic message
Oct 5, 2016
f62afb1
besouro automatic message
Oct 5, 2016
74d0de1
besouro automatic message
Oct 5, 2016
b18c1e6
besouro automatic message
Oct 5, 2016
9aa5dea
besouro automatic message
Oct 5, 2016
0c1859e
besouro automatic message
Oct 5, 2016
f7d1188
besouro automatic message
Oct 5, 2016
da193ec
besouro automatic message
Oct 5, 2016
08bd1e4
besouro automatic message
Oct 5, 2016
35536ce
besouro automatic message
Oct 5, 2016
acb39ce
besouro automatic message
Oct 5, 2016
d03e9ec
besouro automatic message
Oct 5, 2016
6f22039
besouro automatic message
Oct 5, 2016
a3f080a
besouro automatic message
Oct 5, 2016
a80e3d5
besouro automatic message
Oct 5, 2016
dbaa788
besouro automatic message
Oct 5, 2016
a1bed50
besouro automatic message
Oct 5, 2016
b422648
besouro automatic message
Oct 5, 2016
792abcc
besouro automatic message
Oct 5, 2016
7c9dbad
besouro automatic message
Oct 5, 2016
525c607
besouro automatic message
Oct 5, 2016
0cf9a87
besouro automatic message
Oct 5, 2016
f472e18
besouro automatic message
Oct 5, 2016
7221070
besouro automatic message
Oct 5, 2016
328f356
besouro automatic message
Oct 5, 2016
f03ad13
besouro automatic message
Oct 5, 2016
e936a11
besouro automatic message
Oct 5, 2016
38a13b1
besouro automatic message
Oct 5, 2016
4520c61
besouro automatic message
Oct 5, 2016
6406b30
besouro automatic message
Oct 5, 2016
029293c
besouro automatic message
Oct 5, 2016
769826b
besouro automatic message
Oct 5, 2016
84fb5a6
besouro automatic message
Oct 5, 2016
c5e0378
besouro automatic message
Oct 5, 2016
feec292
besouro automatic message
Oct 5, 2016
001ab7e
besouro automatic message
Oct 5, 2016
d7939fe
besouro automatic message
Oct 5, 2016
70f1599
besouro automatic message
Oct 5, 2016
53742c0
besouro automatic message
Oct 5, 2016
15e3578
besouro automatic message
Oct 5, 2016
0bbd9a5
besouro automatic message
Oct 5, 2016
7f0e67d
besouro automatic message
Oct 5, 2016
a682cf7
besouro automatic message
Oct 5, 2016
eff5611
besouro automatic message
Oct 5, 2016
f77b308
add another RomanNumeral class for testing
Oct 5, 2016
053bb4c
refactoring, add tests and logic for invalid roman numbers, test numb…
Oct 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
413 changes: 413 additions & 0 deletions .besouro/20161005142238292/actions.txt

Large diffs are not rendered by default.

465 changes: 465 additions & 0 deletions .besouro/20161005142238292/besouroEpisodes.txt

Large diffs are not rendered by default.

Empty file.
36 changes: 36 additions & 0 deletions .besouro/20161005142238292/randomHeuristicEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
1475666591102 refactoring 2A 32 false
1475666673317 refactoring 2A 41 false
1475666687610 regression 1 0 false
1475666726316 refactoring 2A 5 false
1475666747177 refactoring 2A 2 false
1475666748615 regression 1 0 true
1475666798475 refactoring 2A 2 true
1475666821208 refactoring 2A 3 false
1475666835282 refactoring 2A 1 true
1475666857136 regression 1 1 false
1475666864175 regression 1 0 false
1475667019491 test-addition 1 14 false
1475668292927 refactoring 3 1265 false
1475668308062 regression 1 0 false
1475668442259 refactoring 2A 129 true
1475668482482 regression 2 37 true
1475668818799 refactoring 2A 329 false
1475668826789 regression 1 0 true
1475668948047 test-first 3 102 true
1475669926607 test-first 1 973 true
1475670071488 refactoring 2A 2 false
1475670109461 test-addition 1 15 false
1475670455331 test-first 3 304 true
1475670530371 regression 1 0 false
1475670543197 refactoring 2A 9 false
1475670590110 test-last 1 39 false
1475670593155 regression 1 0 true
1475670633203 test-addition 1 24 false
1475670636950 regression 1 0 false
1475671240466 test-first 1 471 true
1475671301191 refactoring 1A 24 true
1475671623088 test-addition 2 203 true
1475671642139 test-addition 1 9 true
1475671671159 regression 1 1 true
1475671729712 test-first 3 50 true
1475671740993 regression 1 1 true
Empty file.
36 changes: 36 additions & 0 deletions .besouro/20161005142238292/zorroEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
1475666591102 refactoring 2A 32 true
1475666673317 refactoring 2A 82 true
1475666687610 regression 1 14 true
1475666726316 refactoring 2A 38 true
1475666747177 refactoring 2A 20 true
1475666748615 regression 1 1 true
1475666798475 refactoring 2A 49 true
1475666821208 refactoring 2A 22 true
1475666835282 refactoring 2A 14 true
1475666857136 regression 1 21 true
1475666864175 regression 1 7 true
1475667019491 test-addition 1 155 true
1475668292927 refactoring 3 1273 true
1475668308062 regression 1 15 true
1475668442259 refactoring 2A 134 true
1475668482482 regression 2 40 true
1475668818799 refactoring 2A 336 true
1475668826789 regression 1 7 true
1475668948047 test-first 3 121 true
1475669926607 test-first 1 978 true
1475670071488 refactoring 2A 144 true
1475670109461 test-addition 1 37 true
1475670455331 test-first 3 345 true
1475670530371 regression 1 75 true
1475670543197 refactoring 2A 12 true
1475670590110 test-last 1 46 false
1475670593155 regression 1 3 true
1475670633203 test-addition 1 40 true
1475670636950 regression 1 3 true
1475671240466 test-first 1 603 true
1475671301191 refactoring 1A 60 true
1475671623088 test-addition 2 321 true
1475671642139 test-addition 1 19 true
1475671671159 regression 1 29 true
1475671729712 test-first 3 58 true
1475671740993 regression 1 11 true
16 changes: 8 additions & 8 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
34 changes: 17 additions & 17 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
96 changes: 48 additions & 48 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
/bin/
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
/bin/
34 changes: 17 additions & 17 deletions .project
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RomanNumerals</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RomanNumerals</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
126 changes: 123 additions & 3 deletions src/RomanNumerals.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,128 @@

public class RomanNumerals {
public int convertToInteger(String romanNum) {
// To be Implemented
return 0;
private static final char I = 'I';
private static final char V = 'V';
private static final char X = 'X';
private static final char L = 'L';
private static final char C = 'C';
private static final char D = 'D';
private static final char M = 'M';

private boolean subd = false;

public int convertToInteger(String romanNum) throws Exception {
int value = 0;
int lastIndexOfNum = romanNum.length() - 1;

for (int i = lastIndexOfNum; i >= 0; i--) {
checkRepetition(romanNum, lastIndexOfNum, i);
value += parseCharacterToValue(romanNum, i);
}
return value;
}

private void checkRepetition(String romanNum, int lastIndexOfNum, int i) throws Exception {
char c = romanNum.charAt(i);
int repeated = getRepetition(romanNum, lastIndexOfNum, i);
if ((c == I || c == X || c == C || c == M) && repeated > 3) {
throw new Exception("Symbol repeated too many times");
}
else if ((c == V || c == L || c == D) && repeated > 1) {
throw new Exception("Invalid symbol repeated");
}
}

private int getRepetition(String romanNum, int lastIndexOfNum, int i) {
int repeated = 1;
if (i < lastIndexOfNum) {
for (int j = i + 1; j <= lastIndexOfNum; j++) {
if (romanNum.charAt(i) == romanNum.charAt(j)) {
repeated++;
}
else {
break;
}
}
}
return repeated;
}

private int parseCharacterToValue(String romanNum, int i) throws Exception {
int currentVal, nextVal;
currentVal = getCharValue(romanNum.charAt(i));
try {
nextVal = getCharValue(romanNum.charAt(i + 1));
return getCurrentValue(currentVal, nextVal);
}
catch(Exception e) { // @hacks
if (e.getMessage() == "invalid substraction") {
throw e;
}
else {
subd = false;
return currentVal; // when trying to get next of last, it is intended to end up here
}
}
}

private int getCurrentValue(int currentVal, int nextVal) throws Exception {
if (currentVal == nextVal) {
if (subd) {
throw new Exception("invalid substraction");
}
subd = false;
return currentVal;
}
else if (currentVal < nextVal) {
validateSubstraction(currentVal, nextVal);
subd = true;
return -currentVal;
}
else if (currentVal > nextVal) {
subd = false;
return currentVal;
}
return 0;
}

private void validateSubstraction(int currentVal, int nextVal) throws Exception {
if (currentVal == 1 && nextVal > 10) {
throw new Exception("invalid substraction");
}
else if (currentVal == 10 && nextVal > 100) {
throw new Exception("invalid substraction");
}
else if (currentVal == 100 && nextVal > 1000) {
throw new Exception("invalid substraction");
}
else if (currentVal == 5 || currentVal == 50 || currentVal == 500) {
throw new Exception("invalid substraction");
}
}

private int getCharValue(char romanNum) {
if (romanNum == I) {
return 1;
}
else if (romanNum == V) {
return 5;
}
else if (romanNum == X) {
return 10;
}
else if (romanNum == L) {
return 50;
}
else if (romanNum == C) {
return 100;
}
else if (romanNum == D) {
return 500;
}
else if (romanNum == M) {
return 1000;
}
return 0;
}

}
Loading