我最近遇到了一个无法解释的问题.我在这些测试中有很多代码,所以我会尽力在这里捕获这个想法
我的测试看起来像:
describe('main page', function(){
beforeEach(function(done){
addUserToMongoDb(done); // #1
});
afterEach(function(done){
removeUserFromMongoDb(done);
});
context('login', function(){
it('should log the user in, function(){
logUserIn(user_email); // #2 - This line requires the user from the beforeEach
});
});
context('preferences', function(){
before(function(done){ //#3
logUserInBeforeTest(user_email);
});
it('should show the preferences', function(){
doCheckPreferences(); // #4
});
});
});
Run Code Online (Sandbox Code Playgroud)
问题是,beforeEach #1
运行正常.我可以看到它发生在数据库和测试#2
传递中.
但是,首选项上下文中的测试#4
失败,因为它无法找到用户登录它们#3
.
似乎上下文before
在describe之前执行beforeEach
,导致它们失败.如果我移动logUserIn
到it
块中它工作正常.
什么可能导致这个?
我试图在 python 版本3.6.6
和3.7.0
Windows之间切换。我试过了py -3.6.6
,没有用。在 中寻找选项py -h
,没有找到。我看到了几个在 python 版本之间切换2.x
和在文件开头3.x
添加的答案#!python3
。
我可以通过上下移动路径变量来在这些之间切换,但我想知道是否有一个选项可以在版本之间切换,cmd
就像brew switch python version
在 IOS中一样。
谢谢你。
我想比较以下数组的第二个元素:
int[][] intervals = new int[][]{new int[]{0, 30},new int[]{5, 10},new int[]{15, 20}};
Run Code Online (Sandbox Code Playgroud)
我的优先级队列与自定义比较器:
PriorityQueue<int[]> heap = new PriorityQueue(intervals.length, (a, b) -> a[1] - b[1]);
Run Code Online (Sandbox Code Playgroud)
但我收到以下 2 个错误:
Line 8: error: array required, but Object found
PriorityQueue<Integer[]> heap = new PriorityQueue(intervals.length, (a, b) -> a[1] - b[1]);
^
Line 8: error: array required, but Object found
PriorityQueue<Integer[]> heap = new PriorityQueue(intervals.length, (a, b) -> a[1] - b[1]);
Run Code Online (Sandbox Code Playgroud) 刚刚从 spring 初始化程序创建了一个简单的 spring-boot 项目。我去添加一个本地 h2 db 进行测试,但无法登录。似乎它在启动时无法创建测试数据库,但无法弄清楚为什么会这样。
spring:
h2:
console:
enabled: true
path: /h2
datasource:
url: jdbc:h2:mem:testdb;
username: sa
password:
driver-class-name: org.h2.Driver
platform: h2
jpa:
show-sql: true
hibernate:
ddl-auto: create
properties:
hibernate:
dialect=org:
hibernate:
dialect:
H2Dialect: org.hibernate.dialect.H2Dialect
Run Code Online (Sandbox Code Playgroud)
Database "mem:testdb" not found, and IFEXISTS=true, so we cant auto-create it [90146-199] 90146/90146
我试图检查传递的数字是否是有效的完美平方
return True if(math.sqrt(num)%2 == 0 or \
(math.sqrt(num)+1) % 2 == 0 ) else False
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以通过将 if 语句分成两部分来写得更好,例如
return True if(math.sqrt(num)%2 == 0)
elif ((math.sqrt(num)+1) % 2 == 0 )
else False
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我如何在这里使用 elif 或者是否有更好的方法。
谢谢。