是否有断言计数发生的声明?

时间:2019-10-22 07:03:52

标签: groovy assert assertion

是否有声明断言计数范围?

这里是一个例子:我要确保记录总数为3。

断言从第一个偏移量到最后一个偏移量的计数== 3

或断言键/值出现的次数是== 3

回复

SQL> create table ora_table (id number, time_data timestamp, status varchar2(30));

Table created.

SQL> insert into ora_table values (1  , to_timestamp('2019-10-20 12:34:56.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL> insert into ora_table values (1  , to_timestamp('2019-10-22 12:34:56.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL> insert into ora_table values (2  , to_timestamp('2019-10-20 17:34:56.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL> insert into ora_table values (2  , to_timestamp('2019-10-21 12:34:56.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL> insert into ora_table values (3  , to_timestamp('2019-10-23 18:10:10.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'mod_in_ip');

1 row created.

SQL> insert into ora_table values (3  , to_timestamp('2019-10-24 11:10:10.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL> insert into ora_table values (3  , to_timestamp('2019-10-24 12:10:10.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL> insert into ora_table values (4  , to_timestamp('2019-10-25 12:10:10.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL> insert into ora_table values (4  , to_timestamp('2019-10-25 18:10:10.000', 'yyyy-mm-dd hh24:mi:ss.ff'), 'approved');

1 row created.

SQL>
SQL> select id, time_data, trunc(time_data) true_date, trunc(time_data+7/24) mapped_date
  2  from ora_table;

        ID TIME_DATA                          TRUE_DATE MAPPED_DA
---------- ---------------------------------- --------- ---------
         1 20-OCT-19 12.34.56.000000 PM       20-OCT-19 20-OCT-19
         1 22-OCT-19 12.34.56.000000 PM       22-OCT-19 22-OCT-19
         2 20-OCT-19 05.34.56.000000 PM       20-OCT-19 21-OCT-19 <===
         2 21-OCT-19 12.34.56.000000 PM       21-OCT-19 21-OCT-19
         3 23-OCT-19 06.10.10.000000 PM       23-OCT-19 24-OCT-19 <===
         3 24-OCT-19 11.10.10.000000 AM       24-OCT-19 24-OCT-19
         3 24-OCT-19 12.10.10.000000 PM       24-OCT-19 24-OCT-19
         4 25-OCT-19 12.10.10.000000 PM       25-OCT-19 25-OCT-19
         4 25-OCT-19 06.10.10.000000 PM       25-OCT-19 26-OCT-19

9 rows selected.

我在下面尝试过,但是断言失败。

[[key:S1BJTzE=, offset:1416, partition:0, topic:Item, value:eyJvcGVyYXRpb2], [key:S1BJTzE=, offset:1417, partition:0, topic:Item, value:eyJvcGVyYXRpb2],
[key:S1BJTzE=, offset:1418, partition:0, topic:Item, value:eyJvcGVyYXRpb2]]

2 个答案:

答案 0 :(得分:0)

assert test.size()==3

由@daggett提供

答案 1 :(得分:0)

直接方法:

String resp = '[[key:S1BJTzE=, offset:1416, partition:0, topic:Item, value:eyJvcGVyYXRpb2], [key:S1BJTzE=, offset:1417, partition:0, topic:Item, value:eyJvcGVyYXRpb2], [key:S1BJTzE=, offset:1418, partition:0, topic:Item, value:eyJvcGVyYXRpb2]]'
assert 3 == resp.count( 'value:' )