我试图通过在 angular 2 中使用 Jasmine 来编写一个警报测试用例。但是我的测试用例是如何给出错误的,即使我不确定我是否编写了正确的方法。如果有任何想法,请帮助我。
这是我的测试用例:
it('checking showscheduledrequest flow an alert is called',() =>{
let component = fixture.componentInstance;
component['ou'] = 'd';
component['sen'] = 'ddsd';
var oldalert = alert;
oldalert = jasmine.createSpy();
component.handleActionChane('showscheduledrequest');
fixture.autoDetectChanges();
expect(alert).toHaveBeenCalledWith('This is not a valid request');
});Run Code Online (Sandbox Code Playgroud)
以下是考试的引述(1% 的顶尖大学)。
我失败了,因为我的答案与“批准”的答案不同。
我有一种预感,他(教授,著名的 C 专家)的答案是不正确的。
以下是问题后跟“批准”的答案。
以下功能存在潜在错误。它是什么,我将如何修复它?
提示:这与 realloc() 函数的使用有关。请确定您将更改的行号以及您将用什么来替换它们。
Run Code Online (Sandbox Code Playgroud)BOOLEAN lengthen_string(char* string, const char newcontents[]) { int newlen = strlen(string) + strlen(newcontents) + 1; string = realloc(string, newlen); if (!string) { perror("malloc"); return FALSE; } strcat(string, newcontents); return TRUE; }
教授提供的“正确”答案是:
第 4 行: realloc 在分配失败时返回 NULL 指针。这意味着一旦失败,原始数据就会丢失。
要解决此问题,请将 realloc 的结果分配给临时变量并首先对其进行测试。
即:第4行:
Run Code Online (Sandbox Code Playgroud)char * temp=realloc(string, newlen); if(!temp) ... (all remains the same)在旧的第 9 行之后,
string = temp;
有什么想法吗?
顺便说一句,我的回答是 @string 是一个局部变量,函数的原型应该是 char **string,调用者传递一个指向其字符串指针的指针,然后被调用者会将任何 realloc() 返回值分配给 …
代码示例var_inc1.pl:
#!/usr/bin/perl -w
my $x = 0;
$x++;
print "value : ".$x."\n";
Run Code Online (Sandbox Code Playgroud)
输出:
第一次: perl var_inc1.pl
value : 1
Run Code Online (Sandbox Code Playgroud)第二次: perl var_inc1.pl
value : 1
Run Code Online (Sandbox Code Playgroud)但我想要输出
第一次执行: perl var_inc1.pl
value : 1
Run Code Online (Sandbox Code Playgroud)第二次执行: perl var_inc1.pl
value : 2
Run Code Online (Sandbox Code Playgroud)第三次执行: perl var_inc1.pl
value : 3
Run Code Online (Sandbox Code Playgroud)...等等,标量值在每个程序执行时递增.
这两个初始化有什么区别?
char a[] = "string literal";
char *p = "string literal";
Run Code Online (Sandbox Code Playgroud) 我正在使用twitter bootstrap开始一个项目,但是我有一个问题.水平长的空滚动条.我找不到问题,有谁知道这个问题是什么?
谢谢
我的老板要我修改菜单 - 它是用图像制作的,现在他要我用CSS做按钮.我创建了按钮,但现在我需要在鼠标悬停时更改它们,就像在图像中一样:

现在,我真的不是设计师,我更喜欢服务器端的东西,但我需要这样做..我创建的按钮的代码是:
a {
text-transform:none;
color:#F1EFED;
padding:10px;
background-color: #84c225;
}
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个效果?
如何在这里修改图像的大小?:
var image = new Image();
image.src = 'http://www.ziiweb.com/images/logo.png';
image.width = 200; //this is not modifying the width of the image
$('canvas').css({
background: 'url(' + image.src + ')'
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;">
</canvas>Run Code Online (Sandbox Code Playgroud)
我有这个代码:
.blur {
-webkit-animation: blur 5s ;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes blur {
0% { -webkit-filter: blur(0px); }
0% { -webkit-filter: blur(1px); }
50% { -webkit-filter: blur(5px); }
60% { -webkit-filter: blur(5px); }
100% {
opacity: 0;
}
}Run Code Online (Sandbox Code Playgroud)
<img src="http://placehold.it/350x150" class="blur" />Run Code Online (Sandbox Code Playgroud)
基本上我有一个图像,我想要的效果是慢慢淡入,模糊然后淡出。但是当它模糊时,我希望它在那里停留几秒钟,然后淡出图片。你能帮我一下吗?谢谢