diff --git a/benches/large_case.rs b/benches/large_case.rs
index ad9f486d..476228c8 100644
--- a/benches/large_case.rs
+++ b/benches/large_case.rs
@@ -4,8 +4,26 @@ use std::time::Duration;
extern crate criterion;
use self::criterion::*;
+use pubgrub::package::Package;
use pubgrub::solver::{resolve, OfflineDependencyProvider};
-use pubgrub::version::NumberVersion;
+use pubgrub::version::{NumberVersion, SemanticVersion, Version};
+use serde::de::Deserialize;
+use std::hash::Hash;
+
+fn bench<'a, P: Package + Deserialize<'a>, V: Version + Hash + Deserialize<'a>>(
+ b: &mut Bencher,
+ case: &'a str,
+) {
+ let dependency_provider: OfflineDependencyProvider
= ron::de::from_str(&case).unwrap();
+
+ b.iter(|| {
+ for p in dependency_provider.packages() {
+ for n in dependency_provider.versions(p).unwrap() {
+ let _ = resolve(&dependency_provider, p.clone(), n.clone());
+ }
+ }
+ });
+}
fn bench_nested(c: &mut Criterion) {
let mut group = c.benchmark_group("large_cases");
@@ -13,21 +31,17 @@ fn bench_nested(c: &mut Criterion) {
for case in std::fs::read_dir("test-examples").unwrap() {
let case = case.unwrap().path();
-
- group.bench_function(
- format!("{}", case.file_name().unwrap().to_string_lossy()),
- |b| {
- let s = std::fs::read_to_string(&case).unwrap();
- let dependency_provider: OfflineDependencyProvider =
- ron::de::from_str(&s).unwrap();
-
- b.iter(|| {
- for &n in dependency_provider.versions(&0).unwrap() {
- let _ = resolve(&dependency_provider, 0, n);
- }
- });
- },
- );
+ let name = case.file_name().unwrap().to_string_lossy();
+ let data = std::fs::read_to_string(&case).unwrap();
+ if name.ends_with("u16_NumberVersion.ron") {
+ group.bench_function(name, |b| {
+ bench::(b, &data);
+ });
+ } else if name.ends_with("str_SemanticVersion.ron") {
+ group.bench_function(name, |b| {
+ bench::<&str, SemanticVersion>(b, &data);
+ });
+ }
}
group.finish();
diff --git a/tests/proptest.rs b/tests/proptest.rs
index 7aa94a29..d2da3730 100644
--- a/tests/proptest.rs
+++ b/tests/proptest.rs
@@ -478,3 +478,43 @@ proptest! {
}
}
}
+
+#[cfg(feature = "serde")]
+#[test]
+fn large_case() {
+ for case in std::fs::read_dir("test-examples").unwrap() {
+ let case = case.unwrap().path();
+ let name = case.file_name().unwrap().to_string_lossy();
+ eprintln!("{}", name);
+ let data = std::fs::read_to_string(&case).unwrap();
+ if name.ends_with("u16_NumberVersion.ron") {
+ let dependency_provider: OfflineDependencyProvider =
+ ron::de::from_str(&data).unwrap();
+ let mut sat = SatResolve::new(&dependency_provider);
+ for p in dependency_provider.packages() {
+ for n in dependency_provider.versions(p).unwrap() {
+ if let Ok(s) = resolve(&dependency_provider, p.clone(), n.clone()) {
+ assert!(sat.sat_is_valid_solution(&s));
+ } else {
+ assert!(!sat.sat_resolve(p, &n));
+ }
+ }
+ }
+ } else if name.ends_with("str_SemanticVersion.ron") {
+ let dependency_provider: OfflineDependencyProvider<
+ &str,
+ pubgrub::version::SemanticVersion,
+ > = ron::de::from_str(&data).unwrap();
+ let mut sat = SatResolve::new(&dependency_provider);
+ for p in dependency_provider.packages() {
+ for n in dependency_provider.versions(p).unwrap() {
+ if let Ok(s) = resolve(&dependency_provider, p.clone(), n.clone()) {
+ assert!(sat.sat_is_valid_solution(&s));
+ } else {
+ assert!(!sat.sat_resolve(p, &n));
+ }
+ }
+ }
+ }
+ }
+}