假设我有一个数组public void render(Graphics g) {
double xx = x-camera.x;
double yy = y-camera.y;
double zz = z-camera.z;
xx = rotate2d(xx, zz, camera.rot)[0];
zz = rotate2d(xx, zz, camera.rot)[1];
double f = 200/zz;
xx *= f;
yy *= f;
xx += game.width/2;
yy += game.height/2;
if(xx >= 0 && xx <= game.width)
g.drawImage(image, (int) xx, (int) yy, null);
}
private double[] rotate2d(double x, double y, double rad) {
double s = Math.sin(rad);
double c = Math.cos(rad);
double[] pos = new double[2];
pos[0] = x*c-y*s;
pos[1] = y*c+x*s;
return pos;
}
。
我想断言这个数组中确实有两个值是正确的。显然,我可以这样做(使用lodash):
import pandas as pd
import numpy as np
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
utils = importr('utils')
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
utils.install_packages('stargazer')
stargazer = importr('stargazer')
stargazer.stargazer(pandas2ri.py2ri_pandasdataframe(df))
还有更多的Chai-y或Jest-y方法吗?
答案 0 :(得分:1)
最接近的断言方法如下:
这两个选项都不适合,因为您的期望值是一种值类型,并且上面的函数使用===
进行比较(可以更改(至少在Chai中可以更改,但对于我们的情况仍然没有区别)。)
// Jest example
describe('arrayContaining', () => {
const expected = [true, true];
it('does not match: not enough `true` values received', () => {
expect([true, false, false]).not.toEqual(expect.arrayContaining(expected));
});
it('does not match: not enough toatl values received', () => {
expect([true]).not.toEqual(expect.arrayContaining(expected));
});
});
以上两个断言都将失败,这意味着在给定情况下,这些断言规则/功能无法发现期望值与实际值之间的差异。