Skip to content

Commit

Permalink
fix clippy warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkeldenker committed May 6, 2024
1 parent 3c94cb7 commit 6c365f3
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 88 deletions.
5 changes: 2 additions & 3 deletions crates/core/src/ampc/dht/mod.rs
Expand Up @@ -390,7 +390,6 @@ pub mod tests {
.batch_set(
table.clone(),
(0..N)
.into_iter()
.map(|i| {
(
i.to_be_bytes().as_ref().into(),
Expand All @@ -413,9 +412,9 @@ pub mod tests {
res.sort_by_key(|(k, _)| k.clone());
assert_eq!(res.len(), N as usize);

for i in 0..N as usize {
for (i, r) in res.into_iter().enumerate() {
assert_eq!(
res[i],
r,
(
i.to_be_bytes().as_ref().into(),
i.to_be_bytes().as_ref().into(),
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/ampc/dht_conn.rs
Expand Up @@ -497,7 +497,7 @@ mod tests {
.batch_set(vec![(Id(1), Counter(0)), (Id(2), Counter(0))]);

let mut res = tables.id.batch_get(vec![Id(1), Id(2)]);
res.sort_by(|(a, _), (b, _)| a.cmp(&b));
res.sort_by(|(a, _), (b, _)| a.cmp(b));

assert_eq!(res, vec![(Id(1), Counter(0)), (Id(2), Counter(0))]);

Expand All @@ -510,7 +510,7 @@ mod tests {
);

let mut res = tables.id.batch_get(vec![Id(0), Id(1), Id(2)]);
res.sort_by(|(a, _), (b, _)| a.cmp(&b));
res.sort_by(|(a, _), (b, _)| a.cmp(b));

assert_eq!(
res,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/distributed/sonic/mod.rs
Expand Up @@ -293,7 +293,7 @@ mod tests {
.unwrap()
.block_on(async move {
let addr = free_socket_addr();
let server = Server::bind(addr.clone()).await.unwrap();
let server = Server::bind(addr).await.unwrap();
let connection = Connection::create(addr).await.unwrap();

let svr_task = tokio::spawn(async move { svr_fn(server).await });
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Expand Up @@ -237,9 +237,9 @@ fn free_socket_addr() -> std::net::SocketAddr {
use std::net::{Ipv4Addr, TcpListener};

let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).unwrap();
let addr = listener.local_addr().unwrap();


addr
listener.local_addr().unwrap()
}

fn ceil_char_boundary(str: &str, index: usize) -> usize {
Expand Down
6 changes: 6 additions & 0 deletions crates/core/src/query/optic.rs
Expand Up @@ -283,6 +283,7 @@ mod tests {
const CONTENT: &str = "this is the best example website ever this is the best example website ever this is the best example website ever this is the best example website ever this is the best example website ever this is the best example website ever";

#[test]
#[allow(clippy::too_many_lines)]
fn discard_and_boost_hosts() {
let mut index = Index::temporary().expect("Unable to open index");

Expand Down Expand Up @@ -505,6 +506,7 @@ mod tests {
}

#[test]
#[allow(clippy::too_many_lines)]
fn empty_discard() {
let mut index = Index::temporary().expect("Unable to open index");

Expand Down Expand Up @@ -617,6 +619,7 @@ mod tests {
}

#[tokio::test]
#[allow(clippy::too_many_lines)]
async fn liked_hosts() {
let mut index = Index::temporary().expect("Unable to open index");

Expand Down Expand Up @@ -770,6 +773,7 @@ mod tests {
}

#[test]
#[allow(clippy::too_many_lines)]
fn schema_org_search() {
let mut index = Index::temporary().expect("Unable to open index");

Expand Down Expand Up @@ -1101,6 +1105,7 @@ mod tests {
}

#[test]
#[allow(clippy::too_many_lines)]
fn special_pattern_syntax() {
let mut index = Index::temporary().expect("Unable to open index");

Expand Down Expand Up @@ -1380,6 +1385,7 @@ mod tests {
}

#[test]
#[allow(clippy::too_many_lines)]
fn wildcard_edge_cases() {
let mut index = Index::temporary().expect("Unable to open index");

Expand Down
1 change: 1 addition & 0 deletions crates/core/src/ranking/optics.rs
Expand Up @@ -34,6 +34,7 @@ mod tests {
const CONTENT: &str = "this is the best example website ever this is the best example website ever this is the best example website ever this is the best example website ever this is the best example website ever this is the best example website ever";

#[tokio::test]
#[allow(clippy::too_many_lines)]
async fn host_rankings() {
let mut index = Index::temporary().expect("Unable to open index");

Expand Down
76 changes: 36 additions & 40 deletions crates/core/src/webgraph/centrality/mod.rs
Expand Up @@ -120,38 +120,36 @@ mod tests {

#[test]
fn test_top_k() {
let hits = vec![
(SortableFloat(0.0), NodeID::from(0 as u64)),
(SortableFloat(1.0), NodeID::from(1 as u64)),
(SortableFloat(2.0), NodeID::from(2 as u64)),
(SortableFloat(3.0), NodeID::from(3 as u64)),
(SortableFloat(4.0), NodeID::from(4 as u64)),
(SortableFloat(5.0), NodeID::from(5 as u64)),
(SortableFloat(6.0), NodeID::from(6 as u64)),
(SortableFloat(7.0), NodeID::from(7 as u64)),
(SortableFloat(8.0), NodeID::from(8 as u64)),
(SortableFloat(9.0), NodeID::from(9 as u64)),
];
let hits = [(SortableFloat(0.0), NodeID::from(0_u64)),
(SortableFloat(1.0), NodeID::from(1_u64)),
(SortableFloat(2.0), NodeID::from(2_u64)),
(SortableFloat(3.0), NodeID::from(3_u64)),
(SortableFloat(4.0), NodeID::from(4_u64)),
(SortableFloat(5.0), NodeID::from(5_u64)),
(SortableFloat(6.0), NodeID::from(6_u64)),
(SortableFloat(7.0), NodeID::from(7_u64)),
(SortableFloat(8.0), NodeID::from(8_u64)),
(SortableFloat(9.0), NodeID::from(9_u64))];

let top_5 = crate::sorted_k(hits.iter().copied(), 5);
assert_eq!(
top_5,
vec![
(SortableFloat(0.0), NodeID::from(0 as u64)),
(SortableFloat(1.0), NodeID::from(1 as u64)),
(SortableFloat(2.0), NodeID::from(2 as u64)),
(SortableFloat(3.0), NodeID::from(3 as u64)),
(SortableFloat(4.0), NodeID::from(4 as u64))
(SortableFloat(0.0), NodeID::from(0_u64)),
(SortableFloat(1.0), NodeID::from(1_u64)),
(SortableFloat(2.0), NodeID::from(2_u64)),
(SortableFloat(3.0), NodeID::from(3_u64)),
(SortableFloat(4.0), NodeID::from(4_u64))
]
);

let top_3 = crate::sorted_k(hits.iter().copied(), 3);
assert_eq!(
top_3,
vec![
(SortableFloat(0.0), NodeID::from(0 as u64)),
(SortableFloat(1.0), NodeID::from(1 as u64)),
(SortableFloat(2.0), NodeID::from(2 as u64))
(SortableFloat(0.0), NodeID::from(0_u64)),
(SortableFloat(1.0), NodeID::from(1_u64)),
(SortableFloat(2.0), NodeID::from(2_u64))
]
);

Expand All @@ -161,18 +159,16 @@ mod tests {

#[test]
fn test_top_k_reversed() {
let hits = vec![
(SortableFloat(9.0), NodeID::from(9 as u64)),
(SortableFloat(8.0), NodeID::from(8 as u64)),
(SortableFloat(7.0), NodeID::from(7 as u64)),
(SortableFloat(6.0), NodeID::from(6 as u64)),
(SortableFloat(5.0), NodeID::from(5 as u64)),
(SortableFloat(4.0), NodeID::from(4 as u64)),
(SortableFloat(3.0), NodeID::from(3 as u64)),
(SortableFloat(2.0), NodeID::from(2 as u64)),
(SortableFloat(1.0), NodeID::from(1 as u64)),
(SortableFloat(0.0), NodeID::from(0 as u64)),
];
let hits = [(SortableFloat(9.0), NodeID::from(9_u64)),
(SortableFloat(8.0), NodeID::from(8_u64)),
(SortableFloat(7.0), NodeID::from(7_u64)),
(SortableFloat(6.0), NodeID::from(6_u64)),
(SortableFloat(5.0), NodeID::from(5_u64)),
(SortableFloat(4.0), NodeID::from(4_u64)),
(SortableFloat(3.0), NodeID::from(3_u64)),
(SortableFloat(2.0), NodeID::from(2_u64)),
(SortableFloat(1.0), NodeID::from(1_u64)),
(SortableFloat(0.0), NodeID::from(0_u64))];

let top_5 = crate::sorted_k(hits.iter().copied().map(Reverse), 5)
.into_iter()
Expand All @@ -182,11 +178,11 @@ mod tests {
assert_eq!(
top_5,
vec![
(SortableFloat(9.0), NodeID::from(9 as u64)),
(SortableFloat(8.0), NodeID::from(8 as u64)),
(SortableFloat(7.0), NodeID::from(7 as u64)),
(SortableFloat(6.0), NodeID::from(6 as u64)),
(SortableFloat(5.0), NodeID::from(5 as u64))
(SortableFloat(9.0), NodeID::from(9_u64)),
(SortableFloat(8.0), NodeID::from(8_u64)),
(SortableFloat(7.0), NodeID::from(7_u64)),
(SortableFloat(6.0), NodeID::from(6_u64)),
(SortableFloat(5.0), NodeID::from(5_u64))
]
);

Expand All @@ -198,9 +194,9 @@ mod tests {
assert_eq!(
top_3,
vec![
(SortableFloat(9.0), NodeID::from(9 as u64)),
(SortableFloat(8.0), NodeID::from(8 as u64)),
(SortableFloat(7.0), NodeID::from(7 as u64))
(SortableFloat(9.0), NodeID::from(9_u64)),
(SortableFloat(8.0), NodeID::from(8_u64)),
(SortableFloat(7.0), NodeID::from(7_u64))
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/webgraph/id_node_db.rs
Expand Up @@ -72,15 +72,15 @@ mod tests {
let mut db = Id2NodeDb::open(gen_temp_path());

let a_node = Node::from("a".to_string());
let a_id = NodeID::from(0 as u64);
let a_id = NodeID::from(0_u64);

db.put(&a_id, &a_node);
db.flush();

assert_eq!(db.get(&a_id), Some(a_node.clone()));

let b_node = Node::from("b".to_string());
let b_id = NodeID::from(1 as u64);
let b_id = NodeID::from(1_u64);

assert_eq!(db.get(&b_id), None);

Expand Down
13 changes: 7 additions & 6 deletions crates/core/src/webgraph/segment.rs
Expand Up @@ -155,6 +155,7 @@ mod test {
use super::*;

#[test]
#[allow(clippy::too_many_lines)]
fn simple_triangle_graph() {
// ┌────┐
// │ │
Expand All @@ -173,16 +174,16 @@ mod test {
let mut edges = Vec::new();

let a = FullNodeID {
id: NodeID::from(0 as u64),
host: NodeID::from(0 as u64),
id: NodeID::from(0_u64),
host: NodeID::from(0_u64),
};
let b = FullNodeID {
id: NodeID::from(1 as u64),
host: NodeID::from(0 as u64),
id: NodeID::from(1_u64),
host: NodeID::from(0_u64),
};
let c = FullNodeID {
id: NodeID::from(2 as u64),
host: NodeID::from(0 as u64),
id: NodeID::from(2_u64),
host: NodeID::from(0_u64),
};

edges.push(InnerEdge {
Expand Down

0 comments on commit 6c365f3

Please sign in to comment.