Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
roginluo
Jenkins
提交
9ad5632e
J
Jenkins
项目概览
roginluo
/
Jenkins
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ad5632e
编写于
9月 15, 2012
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a reasonable coverage
上级
980a1202
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
1 deletion
+52
-1
src/main/java/ll/Attempt2.java
src/main/java/ll/Attempt2.java
+3
-1
src/main/java/ll/SortedStringList.java
src/main/java/ll/SortedStringList.java
+10
-0
src/test/java/ll/Attempt2Test.java
src/test/java/ll/Attempt2Test.java
+33
-0
src/test/java/ll/FakeMapBuilder.java
src/test/java/ll/FakeMapBuilder.java
+6
-0
未找到文件。
src/main/java/ll/Attempt2.java
浏览文件 @
9ad5632e
...
...
@@ -4,6 +4,7 @@ import java.io.File;
import
java.io.FilenameFilter
;
import
java.io.IOException
;
import
java.util.AbstractMap
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
...
...
@@ -60,7 +61,8 @@ public abstract class Attempt2<R> extends AbstractMap<Integer,R> implements Sort
private
void
loadIdOnDisk
()
{
String
[]
buildDirs
=
dir
.
list
(
createDirectoryFilter
());
if
(
buildDirs
==
null
)
buildDirs
=
new
String
[
0
];
idOnDisk
=
new
SortedStringList
(
Arrays
.
asList
(
buildDirs
));
// wrap into ArrayList to enable mutation
idOnDisk
=
new
SortedStringList
(
new
ArrayList
<
String
>(
Arrays
.
asList
(
buildDirs
)));
}
public
Comparator
<?
super
Integer
>
comparator
()
{
...
...
src/main/java/ll/SortedStringList.java
浏览文件 @
9ad5632e
...
...
@@ -36,6 +36,16 @@ public class SortedStringList extends AbstractList<String> {
return
data
.
size
();
}
@Override
public
String
remove
(
int
index
)
{
return
data
.
remove
(
index
);
}
@Override
public
boolean
remove
(
Object
o
)
{
return
data
.
remove
(
o
);
}
/**
* Finds the index of the entry lower than v.
*/
...
...
src/test/java/ll/Attempt2Test.java
浏览文件 @
9ad5632e
...
...
@@ -6,20 +6,26 @@ import org.junit.Before;
import
org.junit.Rule
;
import
org.junit.Test
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.NoSuchElementException
;
/**
* @author Kohsuke Kawaguchi
*/
public
class
Attempt2Test
extends
Assert
{
// A=1, B=3, C=5
@Rule
public
FakeMapBuilder
aBuilder
=
new
FakeMapBuilder
();
private
FakeMap
a
;
// empty map
@Rule
public
FakeMapBuilder
bBuilder
=
new
FakeMapBuilder
();
private
FakeMap
b
;
@Rule
public
FakeMapBuilder
localBuilder
=
new
FakeMapBuilder
();
@Before
public
void
setUp
()
throws
Exception
{
...
...
@@ -47,6 +53,13 @@ public class Attempt2Test extends Assert {
a
.
get
(
1
).
asserts
(
1
,
"A"
);
}
@Test
public
void
lookupWithBogusKeyType
()
{
assertNull
(
a
.
get
(
null
));
assertNull
(
a
.
get
(
"foo"
));
assertNull
(
a
.
get
(
this
));
}
@Test
public
void
firstKey
()
{
assertEquals
(
1
,
a
.
firstKey
().
intValue
());
...
...
@@ -76,4 +89,24 @@ public class Attempt2Test extends Assert {
assertNull
(
a
.
search
(
99
,
Direction
.
ASC
));
assertNull
(
a
.
search
(-
99
,
Direction
.
DESC
));
}
/**
* If load fails, search needs to gracefully handle it
*/
@Test
public
void
unloadableData
()
throws
IOException
{
FakeMap
m
=
localBuilder
.
add
(
1
,
"A"
).
addUnloadable
(
"B"
).
add
(
5
,
"C"
).
make
();
assertNull
(
m
.
search
(
3
,
Direction
.
EXACT
));
m
.
search
(
3
,
Direction
.
DESC
).
asserts
(
1
,
"A"
);
m
.
search
(
3
,
Direction
.
ASC
).
asserts
(
5
,
"C"
);
}
@Test
public
void
eagerLoading
()
throws
IOException
{
Map
.
Entry
[]
b
=
a
.
entrySet
().
toArray
(
new
Map
.
Entry
[
3
]);
((
Build
)
b
[
0
].
getValue
()).
asserts
(
1
,
"A"
);
((
Build
)
b
[
1
].
getValue
()).
asserts
(
3
,
"B"
);
((
Build
)
b
[
2
].
getValue
()).
asserts
(
5
,
"C"
);
}
}
src/test/java/ll/FakeMapBuilder.java
浏览文件 @
9ad5632e
...
...
@@ -31,6 +31,12 @@ public class FakeMapBuilder implements TestRule {
return
this
;
}
public
FakeMapBuilder
addUnloadable
(
String
id
)
throws
IOException
{
File
build
=
new
File
(
dir
,
id
);
build
.
mkdir
();
return
this
;
}
public
FakeMap
make
()
{
return
new
FakeMap
(
dir
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录