我想在 Rust 中创建一个函数,它生成一个具有随机值的 x 大小的数组。我想问一下如何在 Rust 函数中返回一个数组,如果你能检查我的其余代码是否正常,那就太好了。我很抱歉我的基本问题,但我是初学者。
use rand::prelude::*;
fn generateArray(howManyValues: u32)->[f64]
{
let mut rng = rand::thread_rng();
let array: [f64, howManyValues];
for i in 0..howManyValues
{
array[i] = rng.gen()*100;
}
println!("{:?}", array);
return array;
}
fn main() {
generateArray(10);
}
Run Code Online (Sandbox Code Playgroud) 在我的Locationer课上,我有GetLocationAsync()使用 Xamarin.Essentials: Geolocation 的函数。这个函数工作正常,但我想为这个函数创建单元测试。
我创建了 xUnitTests 项目和单元测试:
public async Task LocationTest()
{
Locationer locationer = new Locationer();
var actual = locationer.GetLocationAsync();
Assert.Equal("test", actual);
}
Run Code Online (Sandbox Code Playgroud)
在 Xamarin Forms 项目中,GetLocationAsync()返回“纬度:46.55465,经度:15.64588,海拔:262”。
在我的单元测试中GetLocationAsync()返回“此程序集的便携式版本中未实现此功能”
是否可以在我的单元测试项目中使用 Xamarin.Essentials: Geolocation?我该如何解决?
我希望最多同时激活 1 个过滤器。我正在使用 Ant 设计表。
对于下面的示例,我希望能够选择“男性”或“女性”,而无需同时选择这两个选项。
代码取自Ant设计文档:
{
title: 'Gender',
dataIndex: 'gender',
filters: [
{ text: 'Male', value: 'male' },
{ text: 'Female', value: 'female' },
],
width: '20%',
},
Run Code Online (Sandbox Code Playgroud)
有什么简单的技巧可以将选择限制为最多 1 个吗?
数据如下:
13 个用户,ID 为 2-13。用户 2 得到 2 个赞,用户 10 得到 2 个赞,用户 3 得到 1 个赞。其余的没有得到任何喜欢。
Prisma 查询如下所示:
return this.prisma.user.findMany({
skip: Number(page) * Number(size),
take: Number(size),
orderBy: { likesReceived: { _count: "desc" }
});
Run Code Online (Sandbox Code Playgroud)
当我向数据库发送查询时,按 likesReceived 排序,我得到以下响应:
| 页 | 尺寸 | 项目 ID |
|---|---|---|
| 0 | 5 | 2, 10, 3, 4, 14 |
| 1 | 5 | 6、7、8、9、11 |
| 2 | 5 | 12, 13, 14 |
用户 14 出现两次,用户 5 缺失。为什么?
按 id 进行附加排序修复了该问题:
return this.prisma.user.findMany({
skip: Number(page) * Number(size),
take: Number(size),
orderBy: [{ likesReceived: { _count: "desc" } …Run Code Online (Sandbox Code Playgroud) antd ×1
arrays ×1
c# ×1
mysql ×1
orm ×1
pagination ×1
prisma ×1
prisma2 ×1
reactjs ×1
rust ×1
unit-testing ×1
web-frontend ×1
xamarin ×1
xunit ×1