mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Upgrade quickcheck to 1.0, adjust code, optimizing a slow test
This commit is contained in:
parent
72ff55ae5d
commit
f9626ade57
19 changed files with 78 additions and 74 deletions
|
|
@ -11,5 +11,5 @@ repository = "https://github.com/greatest-ape/aquatic"
|
|||
byteorder = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = "0.9"
|
||||
quickcheck_macros = "0.9"
|
||||
quickcheck = "1.0"
|
||||
quickcheck_macros = "1.0"
|
||||
|
|
@ -52,7 +52,7 @@ pub struct ResponsePeer {
|
|||
|
||||
#[cfg(test)]
|
||||
impl quickcheck::Arbitrary for IpVersion {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
if bool::arbitrary(g) {
|
||||
IpVersion::IPv4
|
||||
} else {
|
||||
|
|
@ -64,7 +64,7 @@ impl quickcheck::Arbitrary for IpVersion {
|
|||
|
||||
#[cfg(test)]
|
||||
impl quickcheck::Arbitrary for InfoHash {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
let mut bytes = [0u8; 20];
|
||||
|
||||
for byte in bytes.iter_mut() {
|
||||
|
|
@ -78,7 +78,7 @@ impl quickcheck::Arbitrary for InfoHash {
|
|||
|
||||
#[cfg(test)]
|
||||
impl quickcheck::Arbitrary for PeerId {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
let mut bytes = [0u8; 20];
|
||||
|
||||
for byte in bytes.iter_mut() {
|
||||
|
|
@ -92,7 +92,7 @@ impl quickcheck::Arbitrary for PeerId {
|
|||
|
||||
#[cfg(test)]
|
||||
impl quickcheck::Arbitrary for ResponsePeer {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
Self {
|
||||
ip_address: ::std::net::IpAddr::arbitrary(g),
|
||||
port: Port(u16::arbitrary(g)),
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
impl quickcheck::Arbitrary for AnnounceEvent {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
match (bool::arbitrary(g), bool::arbitrary(g)){
|
||||
(false, false) => Self::Started,
|
||||
(true, false) => Self::Started,
|
||||
|
|
@ -303,7 +303,7 @@ mod tests {
|
|||
}
|
||||
|
||||
impl quickcheck::Arbitrary for ConnectRequest {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
Self {
|
||||
transaction_id: TransactionId(i32::arbitrary(g)),
|
||||
}
|
||||
|
|
@ -311,7 +311,7 @@ mod tests {
|
|||
}
|
||||
|
||||
impl quickcheck::Arbitrary for AnnounceRequest {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
Self {
|
||||
connection_id: ConnectionId(i64::arbitrary(g)),
|
||||
transaction_id: TransactionId(i32::arbitrary(g)),
|
||||
|
|
@ -330,7 +330,7 @@ mod tests {
|
|||
}
|
||||
|
||||
impl quickcheck::Arbitrary for ScrapeRequest {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
let info_hashes = (0..u8::arbitrary(g)).map(|_| {
|
||||
InfoHash::arbitrary(g)
|
||||
}).collect();
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
impl quickcheck::Arbitrary for TorrentScrapeStatistics {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
Self {
|
||||
seeders: NumberOfPeers(i32::arbitrary(g)),
|
||||
completed: NumberOfDownloads(i32::arbitrary(g)),
|
||||
|
|
@ -289,7 +289,7 @@ mod tests {
|
|||
}
|
||||
|
||||
impl quickcheck::Arbitrary for ConnectResponse {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
Self {
|
||||
connection_id: ConnectionId(i64::arbitrary(g)),
|
||||
transaction_id: TransactionId(i32::arbitrary(g)),
|
||||
|
|
@ -298,7 +298,7 @@ mod tests {
|
|||
}
|
||||
|
||||
impl quickcheck::Arbitrary for AnnounceResponse {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
let peers = (0..u8::arbitrary(g)).map(|_| {
|
||||
ResponsePeer::arbitrary(g)
|
||||
}).collect();
|
||||
|
|
@ -314,7 +314,7 @@ mod tests {
|
|||
}
|
||||
|
||||
impl quickcheck::Arbitrary for ScrapeResponse {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
let torrent_stats = (0..u8::arbitrary(g)).map(|_| {
|
||||
TorrentScrapeStatistics::arbitrary(g)
|
||||
}).collect();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue