Skip to content

Commit 7bb1b7b

Browse files
authored
Added test 601.
1 parent e21e95b commit 7bb1b7b

File tree

2 files changed

+84
-7
lines changed
  • src
    • main/java/g0601_0700/s0601_human_traffic_of_stadium
    • test/java/g0601_0700/s0601_human_traffic_of_stadium

2 files changed

+84
-7
lines changed

src/main/java/g0601_0700/s0601_human_traffic_of_stadium/script.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ from
55
(select
66

77
id, visit_date, people,
8-
lead(people, 1) over ( order by id) as 1_next,
9-
lead(people, 2) over ( order by id) as 2_next,
10-
lag(people, 1) over ( order by id) as 1_prev,
11-
lag(people, 2) over ( order by id) as 2_prev
8+
lead(people, 1) over ( order by id) as one_next,
9+
lead(people, 2) over ( order by id) as two_next,
10+
lag(people, 1) over ( order by id) as one_prev,
11+
lag(people, 2) over ( order by id) as two_prev
1212

1313
from Stadium
1414
) a
1515

1616
where (people >= 100) and
1717

1818
(
19-
(1_next >= 100 and 2_next >=100) or
20-
(1_prev >= 100 and 2_prev >=100) or
21-
(1_prev >= 100 and 1_next >=100)
19+
(one_next >= 100 and two_next >=100) or
20+
(one_prev >= 100 and two_prev >=100) or
21+
(one_prev >= 100 and one_next >=100)
2222
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package g0601_0700.s0601_human_traffic_of_stadium;
2+
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import java.io.BufferedReader;
7+
import java.io.FileNotFoundException;
8+
import java.io.FileReader;
9+
import java.sql.Connection;
10+
import java.sql.ResultSet;
11+
import java.sql.SQLException;
12+
import java.sql.Statement;
13+
import java.util.stream.Collectors;
14+
import javax.sql.DataSource;
15+
import org.junit.jupiter.api.Test;
16+
import org.zapodot.junit.db.annotations.EmbeddedDatabase;
17+
import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest;
18+
import org.zapodot.junit.db.common.CompatibilityMode;
19+
20+
@EmbeddedDatabaseTest(
21+
compatibilityMode = CompatibilityMode.MySQL,
22+
initialSqls =
23+
"CREATE TABLE Stadium(id INTEGER, visit_date DATE PRIMARY KEY, people INTEGER); "
24+
+ "INSERT INTO Stadium(id, visit_date, people)"
25+
+ " VALUES (1, '2017-01-01', 10); "
26+
+ "INSERT INTO Stadium(id, visit_date, people)"
27+
+ " VALUES (2, '2017-01-02', 109); "
28+
+ "INSERT INTO Stadium(id, visit_date, people)"
29+
+ " VALUES (3, '2017-01-03', 150); "
30+
+ "INSERT INTO Stadium(id, visit_date, people)"
31+
+ " VALUES (4, '2017-01-04', 99); "
32+
+ "INSERT INTO Stadium(id, visit_date, people)"
33+
+ " VALUES (5, '2017-01-05', 145); "
34+
+ "INSERT INTO Stadium(id, visit_date, people)"
35+
+ " VALUES (6, '2017-01-06', 1455); "
36+
+ "INSERT INTO Stadium(id, visit_date, people)"
37+
+ " VALUES (7, '2017-01-07', 199); "
38+
+ "INSERT INTO Stadium(id, visit_date, people)"
39+
+ " VALUES (8, '2017-01-09', 188); ")
40+
class MysqlTest {
41+
@Test
42+
void testScript(@EmbeddedDatabase DataSource dataSource)
43+
throws SQLException, FileNotFoundException {
44+
try (final Connection connection = dataSource.getConnection()) {
45+
try (final Statement statement = connection.createStatement();
46+
final ResultSet resultSet =
47+
statement.executeQuery(
48+
new BufferedReader(
49+
new FileReader(
50+
"src/main/java/g0601_0700/"
51+
+ "s0601_human_traffic"
52+
+ "_of_stadium"
53+
+ "/script.sql"))
54+
.lines()
55+
.collect(Collectors.joining("\n"))
56+
.replaceAll("#.*?\\r?\\n", ""))) {
57+
assertThat(resultSet.next(), equalTo(true));
58+
assertThat(resultSet.getInt(1), equalTo(5));
59+
assertThat(resultSet.getDate(2).toString(), equalTo("2017-01-05"));
60+
assertThat(resultSet.getInt(3), equalTo(145));
61+
assertThat(resultSet.next(), equalTo(true));
62+
assertThat(resultSet.getInt(1), equalTo(6));
63+
assertThat(resultSet.getDate(2).toString(), equalTo("2017-01-06"));
64+
assertThat(resultSet.getInt(3), equalTo(1455));
65+
assertThat(resultSet.next(), equalTo(true));
66+
assertThat(resultSet.getInt(1), equalTo(7));
67+
assertThat(resultSet.getDate(2).toString(), equalTo("2017-01-07"));
68+
assertThat(resultSet.getInt(3), equalTo(199));
69+
assertThat(resultSet.next(), equalTo(true));
70+
assertThat(resultSet.getInt(1), equalTo(8));
71+
assertThat(resultSet.getDate(2).toString(), equalTo("2017-01-09"));
72+
assertThat(resultSet.getInt(3), equalTo(188));
73+
assertThat(resultSet.next(), equalTo(false));
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)