小编Pet*_*ryl的帖子

如何使JUnit打印断言和结果

我有一些像这样的测试:

@Test
public void test01()
{
    Position p = getPositionAt('a', 1);
    assertNotNull("a1 exists", p);
    assertNotNull("figure exists a1", p.getFigure());

    p = getPositionAt('a', 2);
    assertNotNull("exists a2", p);
    assertNull("figure exists a2", p.getFigure());

    p = getPositionAt('b', 1);
    assertNotNull("exists b1", p);
    assertNull("figure exists b1", p.getFigure());
}
Run Code Online (Sandbox Code Playgroud)

运行测试时我需要的是将每个断言消息打印到stdout然后打断断言的结果.

这是测试类需要的格式:

a1 exists -success
figure exists a1 -success
exists a2 -success
figure exists a2 -succcess
exists b1 -succcess
figure exists b1 -failed
Run Code Online (Sandbox Code Playgroud)

但是怎么做呢?我是JUnit的新工作者并不知道.是否有使用runnerssuites?或者存在任何assertSuccess(),assertFailed()方法?谢谢你的任何提示.

java testing junit junit4

28
推荐指数
2
解决办法
7万
查看次数

getaddrinfo内存泄漏

我有这个代码来获取有关IPv4地址的信息:

struct addrinfo hints, *info = NULL;
char addr4[INET_ADDRSTRLEN];

memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_INET;

if (!getaddrinfo(argv[hostPara], NULL, &hints, &info)) {
    inet_ntop(AF_INET, &((const sockaddr_in *)info->ai_addr)->sin_addr, addr4, INET_ADDRSTRLEN);
}
if (info != NULL) {
    freeaddrinfo(info);
}
Run Code Online (Sandbox Code Playgroud)

但如果我测试argv [hostPara]是"www.google.com"我从valgrind得到这个:

==3632== 168 bytes in 1 blocks are still reachable in loss record 1 of 1
==3632==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3632==    by 0x524B5B8: make_request (check_pf.c:249)
==3632==    by 0x524BA53: __check_pf (check_pf.c:342)
==3632==    by 0x5201134: getaddrinfo (getaddrinfo.c:2458)
==3632==    by 0x40186B: main …
Run Code Online (Sandbox Code Playgroud)

c c++ ubuntu valgrind getaddrinfo

16
推荐指数
2
解决办法
2807
查看次数

按不同顺序的多个键对字典列表进行排序

我需要对这个词典列表进行排序:

[ {K: 1, B: 2, A: 3, Z: 4, ... } , ... ] 
Run Code Online (Sandbox Code Playgroud)

订购应该是:

  • K - 下降
  • B - 下降
  • A - 升序
  • Z - 上升

我只发现了如何按升序或降序(reverse=True)排序所有键:

stats.sort(key=lambda x: (x['K'], x['B'], x['A'], x['Z']))
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助,如何按键不同的顺序排序?

python sorting dictionary list python-2.7

16
推荐指数
1
解决办法
7752
查看次数

Google自定义搜索JSON API配额和结算

我只是在使用JSON API在GSS(谷歌站点搜索)和CSE(自定义搜索引擎)之间做出决定.但我对JSON API计费有点困惑.

我批准的启动预算是每年100美元,每年可以在GSS中查询20 000个查询,但是我将在JSON API中获得多少查询以及如何设置配额以不超过预算?

我有意见谷歌如何计费:

1个查询的价格是0.005 $ = 5 $/1000个查询=> https://developers.google.com/custom-search/json-api/v1/overview#pricing

谷歌添加日查询(超过100免费),然后创建月份帐单.所以我的配额必须设置为154(100免费+ 54):

每天54次查询*31天*12个月= 20 088次查询*0.005 $ = 100,44 $这是我将支付的最高金额(可能更少).

我对吗?或谷歌以不同的方式进行结算?

google-app-engine google-api google-search-api google-custom-search

5
推荐指数
0
解决办法
1909
查看次数

SSH连接由远程主机关闭

我有问题连接SSH到远程主机,但只在我的家庭网络(提供商).如果我在另一个网络(我在同一个城市的朋友 - 不同的提供商),连接工作完美.Ping到服务器(在我家)工作.这个问题我只有这个服务器.如果我尝试从家庭网络连接到其他主机,它可以工作.我该怎么办?

nich@ubuntu:/etc$ ssh -vvv xxx@www.sci.muni.cz
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to www.sci.muni.cz [147.251.24.3] port 22.
debug1: Connection established.
debug1: identity file /home/nich/.ssh/id_rsa type -1
debug1: identity file /home/nich/.ssh/id_rsa-cert type -1
debug1: identity file /home/nich/.ssh/id_dsa type -1
debug1: identity file /home/nich/.ssh/id_dsa-cert type -1
debug1: identity file /home/nich/.ssh/id_ecdsa type -1
debug1: identity file /home/nich/.ssh/id_ecdsa-cert type -1
ssh_exchange_identification: Connection closed …
Run Code Online (Sandbox Code Playgroud)

linux ssh ubuntu

4
推荐指数
1
解决办法
2万
查看次数

通过 DataGridTextColumn 验证禁用/启用按钮

我有这个DataGrid

<DataGrid ItemsSource="{Binding CustomerXml}" 
     Name="customersDataGrid" AutoGenerateColumns="False" DataContext="{Binding}">
     <DataGrid.Columns>
         <DataGridTextColumn Header="Name">
             <DataGridTextColumn.Binding>
                 <Binding Path="Name" ValidatesOnDataErrors="True" 
                     UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
                     <Binding.ValidationRules>
                         <local:NameValidationRule/>
                     </Binding.ValidationRules>
                 </Binding>
             </DataGridTextColumn.Binding>
         </DataGridTextColumn>

         ...

     </DataGrid.Columns>          
 </DataGrid>
Run Code Online (Sandbox Code Playgroud)

我正在尝试按ValidationRule结果禁用和启用保存按钮。

<Button Content="Save" Name="save" Click="save_Click">
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Setter Property="IsEnabled" Value="false" />
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition 
                             Binding="{Binding ElementName=customersDataGrid, 
                             Path=(Validation.HasError)}" Value="false" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="IsEnabled" Value="true" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>
Run Code Online (Sandbox Code Playgroud)

但如果ValidationResult设置为 true 或 false,按钮仍处于禁用状态。

validation wpf datagrid button multidatatrigger

4
推荐指数
1
解决办法
2759
查看次数

snprintf()不适用于就地修改字符串

char symbols[16] = "";
int index = 0;
while (1)
{
     if (index % 2)
         snprintf(symbols, sizeof symbols, "a%s", symbols);
     else
         snprintf(symbols, sizeof symbols, "b%s", symbols);

     index++;

     printf("%s\n", symbols);
}
Run Code Online (Sandbox Code Playgroud)

输出如何显示:a => bb => aaa => bbbb

我希望输出看起来:a => ba => aba => baba

c string concatenation char

2
推荐指数
1
解决办法
442
查看次数

字符串向量仍然可以访问

我有这个字符串向量的示例代码:

vector<string> strings;
strings.push_back(argv[0]);
cout << strings[0] << endl;
strings.clear();

exit(0);
Run Code Online (Sandbox Code Playgroud)

但是valgrind说:

==26012== HEAP SUMMARY:
==26012==     in use at exit: 8 bytes in 1 blocks
==26012==   total heap usage: 2 allocs, 1 frees, 41 bytes allocated
==26012== 
==26012== 8 bytes in 1 blocks are still reachable in loss record 1 of 1
==26012==    at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26012==    by 0x401DCF: __gnu_cxx::new_allocator<std::string>::allocate(unsigned long, void const*) (new_allocator.h:92)
==26012==    by 0x401BD8: std::_Vector_base<std::string, std::allocator<std::string> >::_M_allocate(unsigned long) (in /home/nich/IPK/2/client)
==26012==    by 0x401706: …
Run Code Online (Sandbox Code Playgroud)

c++ valgrind vector

1
推荐指数
1
解决办法
930
查看次数