Skip to content

Commit 4e558f7

Browse files
author
chenweijie
committed
测试类的添加
1 parent 6cb7891 commit 4e558f7

File tree

4 files changed

+100
-25
lines changed

4 files changed

+100
-25
lines changed

src/main/java/com/chen/api/util/regex/RegexTest1.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.junit.Test;
44

5+
import java.util.Arrays;
56
import java.util.regex.Matcher;
67
import java.util.regex.Pattern;
78

@@ -12,14 +13,14 @@ public class RegexTest1 {
1213

1314

1415
@Test
15-
public void testMatches(){
16+
public void testMatches() {
1617
String regex = "[1-9][0-1]*[.]?[0-9]*";
17-
String str1 ="12r34a5";
18-
if (regex.matches(str1)){
19-
System.out.println("matches:"+str1);
20-
}else {
21-
str1= str1.replaceAll("\\D+","");
22-
System.out.println(" not matches:"+str1);
18+
String str1 = "12r34a5";
19+
if (regex.matches(str1)) {
20+
System.out.println("matches:" + str1);
21+
} else {
22+
str1 = str1.replaceAll("\\D+", "");
23+
System.out.println(" not matches:" + str1);
2324
}
2425
}
2526

@@ -46,8 +47,13 @@ public void testFindAndMatch() {
4647
System.out.println(m.matches());
4748
}
4849

49-
50-
50+
@Test
51+
public void testNumber() {
52+
// String patterStr = "^([0-9]\\d*\\.\\d*)|(0\\.\\d*[0-9]\\d*)|([0-9]\\d*)$";
53+
String patterStr = "^[-]?[0.0-9.0]+$";
54+
String[] strings = {"3", "4", "5", "1.0", "0.2", "44", "-2", "1.111", "100.5", "0", "0.0", "-0.2", "d", "4200.22222"};
55+
Arrays.asList(strings).forEach(str -> System.out.println(str + ",matches:" + str.matches(patterStr)));
56+
}
5157

5258

5359
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.chen.api.util.thread.semaphor;
2+
3+
import java.util.Date;
4+
import java.util.Random;
5+
import java.util.concurrent.Semaphore;
6+
7+
/**
8+
* 信号量-根据阀值做一些访问控制
9+
*
10+
* @author Chen WeiJie
11+
* @date 2017-11-22 17:00
12+
**/
13+
public class SemaphoreTest {
14+
15+
16+
private final static Semaphore MAX_SEMA_PHORE = new Semaphore(10);
17+
18+
19+
public static void main(String[] args) {
20+
21+
22+
for (int i = 0; i < 100; i++) {
23+
24+
final int num = i;
25+
26+
final Random random = new Random();
27+
28+
new Thread(() -> {
29+
boolean acquired = false;
30+
try {
31+
MAX_SEMA_PHORE.acquire();
32+
acquired = true;
33+
System.out.println("我是线程:" + num + " 我获得了使用权!" + new Date());
34+
long time = 1000 * Math.max(1, Math.abs(random.nextInt() % 10));
35+
Thread.sleep(time);
36+
System.out.println("我是线程:" + num + " 我执行完了!" + new Date());
37+
} catch (Exception e) {
38+
e.printStackTrace();
39+
} finally {
40+
if (acquired) {
41+
MAX_SEMA_PHORE.release();
42+
}
43+
}
44+
}).start();
45+
}
46+
}
47+
48+
49+
50+
51+
52+
53+
}

src/main/test/com/chen/test/Test.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.chen.test;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
* User: chenweijie
7+
* Date: 10/23/17
8+
* Time: 8:25 PM
9+
* Description:
10+
*/
11+
public class TestCase {
12+
13+
14+
@Test
15+
public void test() {
16+
int COUNT_BITS = Integer.SIZE - 3;
17+
int CAPACITY = (1 << COUNT_BITS) - 1;
18+
19+
final int RUNNING = -1 << COUNT_BITS;
20+
final int SHUTDOWN = 0 << COUNT_BITS;
21+
final int STOP = 1 << COUNT_BITS;
22+
final int TIDYING = 2 << COUNT_BITS;
23+
final int TERMINATED = 3 << COUNT_BITS;
24+
25+
26+
}
27+
28+
29+
30+
31+
32+
}

0 commit comments

Comments
 (0)