organization

This commit is contained in:
Brandon Thomas committed 2026-03-24 22:00:16 -04:00
1 parent d1b7cc35fd
commit 7c0c75e426
1 file changed
+104 -100
@@ -346,121 +346,125 @@ mod tests {
use crate::requests::prepare_file_upload::prepare_file_upload::{prepare_file_upload, PrepareFileUploadArgs};
use crate::requests::upload_file::upload_file::{upload_file, UploadFileArgs};
fn dummy_session() -> Seedance2ProSession {
Seedance2ProSession::from_cookies_string(String::new())
}
fn args_with(model_type: ModelType, duration_seconds: u8, batch_count: BatchCount) -> GenerateVideoArgs<'static> {
// Safety: the dummy session is leaked so the reference is 'static for test purposes.
let session = Box::leak(Box::new(dummy_session()));
GenerateVideoArgs {
session,
model_type,
prompt: String::new(),
resolution: Resolution::Square1x1,
duration_seconds,
batch_count,
start_frame_url: None,
end_frame_url: None,
reference_image_urls: None,
reference_video_urls: None,
reference_audio_urls: None,
use_face_blur_hack: None,
host_override: None,
mod pricing_tests {
use super::*;
fn dummy_session() -> Seedance2ProSession {
Seedance2ProSession::from_cookies_string(String::new())
}
}
fn pro(duration_seconds: u8, batch_count: BatchCount) -> GenerateVideoArgs<'static> {
args_with(ModelType::Seedance2Pro, duration_seconds, batch_count)
}
fn args_with(model_type: ModelType, duration_seconds: u8, batch_count: BatchCount) -> GenerateVideoArgs<'static> {
// Safety: the dummy session is leaked so the reference is 'static for test purposes.
let session = Box::leak(Box::new(dummy_session()));
GenerateVideoArgs {
session,
model_type,
prompt: String::new(),
resolution: Resolution::Square1x1,
duration_seconds,
batch_count,
start_frame_url: None,
end_frame_url: None,
reference_image_urls: None,
reference_video_urls: None,
reference_audio_urls: None,
use_face_blur_hack: None,
host_override: None,
}
}
fn fast(duration_seconds: u8, batch_count: BatchCount) -> GenerateVideoArgs<'static> {
args_with(ModelType::Seedance2Fast, duration_seconds, batch_count)
}
fn pro(duration_seconds: u8, batch_count: BatchCount) -> GenerateVideoArgs<'static> {
args_with(ModelType::Seedance2Pro, duration_seconds, batch_count)
}
#[test]
fn test_estimate_credits_pro() {
// 40 credits per second, batch 1
assert_eq!(pro(4, BatchCount::One).estimate_credits(), 160);
assert_eq!(pro(5, BatchCount::One).estimate_credits(), 200);
assert_eq!(pro(6, BatchCount::One).estimate_credits(), 240);
assert_eq!(pro(7, BatchCount::One).estimate_credits(), 280);
assert_eq!(pro(15, BatchCount::One).estimate_credits(), 600);
fn fast(duration_seconds: u8, batch_count: BatchCount) -> GenerateVideoArgs<'static> {
args_with(ModelType::Seedance2Fast, duration_seconds, batch_count)
}
// Batch 2 = 2×
assert_eq!(pro(4, BatchCount::Two).estimate_credits(), 320);
assert_eq!(pro(5, BatchCount::Two).estimate_credits(), 400);
assert_eq!(pro(15, BatchCount::Two).estimate_credits(), 1200);
#[test]
fn test_estimate_credits_pro() {
// 40 credits per second, batch 1
assert_eq!(pro(4, BatchCount::One).estimate_credits(), 160);
assert_eq!(pro(5, BatchCount::One).estimate_credits(), 200);
assert_eq!(pro(6, BatchCount::One).estimate_credits(), 240);
assert_eq!(pro(7, BatchCount::One).estimate_credits(), 280);
assert_eq!(pro(15, BatchCount::One).estimate_credits(), 600);
// Batch 4 = 3× (not 4×)
assert_eq!(pro(4, BatchCount::Four).estimate_credits(), 480);
assert_eq!(pro(5, BatchCount::Four).estimate_credits(), 600);
assert_eq!(pro(15, BatchCount::Four).estimate_credits(), 1800);
}
// Batch 2 = 2×
assert_eq!(pro(4, BatchCount::Two).estimate_credits(), 320);
assert_eq!(pro(5, BatchCount::Two).estimate_credits(), 400);
assert_eq!(pro(15, BatchCount::Two).estimate_credits(), 1200);
#[test]
fn test_estimate_credits_fast() {
// 28 credits per second, batch 1
assert_eq!(fast(4, BatchCount::One).estimate_credits(), 112);
assert_eq!(fast(5, BatchCount::One).estimate_credits(), 140);
assert_eq!(fast(6, BatchCount::One).estimate_credits(), 168);
assert_eq!(fast(7, BatchCount::One).estimate_credits(), 196);
assert_eq!(fast(15, BatchCount::One).estimate_credits(), 420);
// Batch 4 = 3× (not 4×)
assert_eq!(pro(4, BatchCount::Four).estimate_credits(), 480);
assert_eq!(pro(5, BatchCount::Four).estimate_credits(), 600);
assert_eq!(pro(15, BatchCount::Four).estimate_credits(), 1800);
}
// Batch 2 = 2×
assert_eq!(fast(4, BatchCount::Two).estimate_credits(), 224);
assert_eq!(fast(5, BatchCount::Two).estimate_credits(), 280);
assert_eq!(fast(15, BatchCount::Two).estimate_credits(), 840);
#[test]
fn test_estimate_credits_fast() {
// 28 credits per second, batch 1
assert_eq!(fast(4, BatchCount::One).estimate_credits(), 112);
assert_eq!(fast(5, BatchCount::One).estimate_credits(), 140);
assert_eq!(fast(6, BatchCount::One).estimate_credits(), 168);
assert_eq!(fast(7, BatchCount::One).estimate_credits(), 196);
assert_eq!(fast(15, BatchCount::One).estimate_credits(), 420);
// Batch 4 = 3× (not 4×)
assert_eq!(fast(4, BatchCount::Four).estimate_credits(), 336);
assert_eq!(fast(5, BatchCount::Four).estimate_credits(), 420);
assert_eq!(fast(15, BatchCount::Four).estimate_credits(), 1260);
}
// Batch 2 = 2×
assert_eq!(fast(4, BatchCount::Two).estimate_credits(), 224);
assert_eq!(fast(5, BatchCount::Two).estimate_credits(), 280);
assert_eq!(fast(15, BatchCount::Two).estimate_credits(), 840);
#[test]
fn test_estimate_cost_usd_cents_pro() {
// 40 credits per second, batch 1
assert_eq!(pro(4, BatchCount::One).estimate_cost_in_usd_cents(), 64);
assert_eq!(pro(5, BatchCount::One).estimate_cost_in_usd_cents(), 80);
assert_eq!(pro(6, BatchCount::One).estimate_cost_in_usd_cents(), 96);
assert_eq!(pro(7, BatchCount::One).estimate_cost_in_usd_cents(), 112);
assert_eq!(pro(15, BatchCount::One).estimate_cost_in_usd_cents(), 240);
// Batch 4 = 3× (not 4×)
assert_eq!(fast(4, BatchCount::Four).estimate_credits(), 336);
assert_eq!(fast(5, BatchCount::Four).estimate_credits(), 420);
assert_eq!(fast(15, BatchCount::Four).estimate_credits(), 1260);
}
// Batch 2 = 2×
assert_eq!(pro(4, BatchCount::Two).estimate_cost_in_usd_cents(), 128);
assert_eq!(pro(5, BatchCount::Two).estimate_cost_in_usd_cents(), 160);
assert_eq!(pro(15, BatchCount::Two).estimate_cost_in_usd_cents(), 480);
#[test]
fn test_estimate_cost_usd_cents_pro() {
// 40 credits per second, batch 1
assert_eq!(pro(4, BatchCount::One).estimate_cost_in_usd_cents(), 64);
assert_eq!(pro(5, BatchCount::One).estimate_cost_in_usd_cents(), 80);
assert_eq!(pro(6, BatchCount::One).estimate_cost_in_usd_cents(), 96);
assert_eq!(pro(7, BatchCount::One).estimate_cost_in_usd_cents(), 112);
assert_eq!(pro(15, BatchCount::One).estimate_cost_in_usd_cents(), 240);
// Batch 4 = 3× (not 4×)
assert_eq!(pro(4, BatchCount::Four).estimate_cost_in_usd_cents(), 192);
assert_eq!(pro(5, BatchCount::Four).estimate_cost_in_usd_cents(), 240);
assert_eq!(pro(15, BatchCount::Four).estimate_cost_in_usd_cents(), 720);
}
// Batch 2 = 2×
assert_eq!(pro(4, BatchCount::Two).estimate_cost_in_usd_cents(), 128);
assert_eq!(pro(5, BatchCount::Two).estimate_cost_in_usd_cents(), 160);
assert_eq!(pro(15, BatchCount::Two).estimate_cost_in_usd_cents(), 480);
#[test]
fn test_estimate_cost_usd_cents_fast() {
// 28 credits per second, batch 1
// 28 * 4 = 112 credits => 112 / 250 * 100 = 44.8 => 45 cents
assert_eq!(fast(4, BatchCount::One).estimate_cost_in_usd_cents(), 45);
// 28 * 5 = 140 credits => 140 / 250 * 100 = 56 cents
assert_eq!(fast(5, BatchCount::One).estimate_cost_in_usd_cents(), 56);
// 28 * 6 = 168 credits => 168 / 250 * 100 = 67.2 => 67 cents
assert_eq!(fast(6, BatchCount::One).estimate_cost_in_usd_cents(), 67);
// 28 * 7 = 196 credits => 196 / 250 * 100 = 78.4 => 78 cents
assert_eq!(fast(7, BatchCount::One).estimate_cost_in_usd_cents(), 78);
// 28 * 15 = 420 credits => 420 / 250 * 100 = 168 cents
assert_eq!(fast(15, BatchCount::One).estimate_cost_in_usd_cents(), 168);
// Batch 4 = 3× (not 4×)
assert_eq!(pro(4, BatchCount::Four).estimate_cost_in_usd_cents(), 192);
assert_eq!(pro(5, BatchCount::Four).estimate_cost_in_usd_cents(), 240);
assert_eq!(pro(15, BatchCount::Four).estimate_cost_in_usd_cents(), 720);
}
// Batch 2 = 2×
assert_eq!(fast(4, BatchCount::Two).estimate_cost_in_usd_cents(), 90);
assert_eq!(fast(5, BatchCount::Two).estimate_cost_in_usd_cents(), 112);
assert_eq!(fast(15, BatchCount::Two).estimate_cost_in_usd_cents(), 336);
#[test]
fn test_estimate_cost_usd_cents_fast() {
// 28 credits per second, batch 1
// 28 * 4 = 112 credits => 112 / 250 * 100 = 44.8 => 45 cents
assert_eq!(fast(4, BatchCount::One).estimate_cost_in_usd_cents(), 45);
// 28 * 5 = 140 credits => 140 / 250 * 100 = 56 cents
assert_eq!(fast(5, BatchCount::One).estimate_cost_in_usd_cents(), 56);
// 28 * 6 = 168 credits => 168 / 250 * 100 = 67.2 => 67 cents
assert_eq!(fast(6, BatchCount::One).estimate_cost_in_usd_cents(), 67);
// 28 * 7 = 196 credits => 196 / 250 * 100 = 78.4 => 78 cents
assert_eq!(fast(7, BatchCount::One).estimate_cost_in_usd_cents(), 78);
// 28 * 15 = 420 credits => 420 / 250 * 100 = 168 cents
assert_eq!(fast(15, BatchCount::One).estimate_cost_in_usd_cents(), 168);
// Batch 4 = 3× (not 4×)
assert_eq!(fast(4, BatchCount::Four).estimate_cost_in_usd_cents(), 134);
assert_eq!(fast(5, BatchCount::Four).estimate_cost_in_usd_cents(), 168);
assert_eq!(fast(15, BatchCount::Four).estimate_cost_in_usd_cents(), 504);
// Batch 2 = 2×
assert_eq!(fast(4, BatchCount::Two).estimate_cost_in_usd_cents(), 90);
assert_eq!(fast(5, BatchCount::Two).estimate_cost_in_usd_cents(), 112);
assert_eq!(fast(15, BatchCount::Two).estimate_cost_in_usd_cents(), 336);
// Batch 4 = 3× (not 4×)
assert_eq!(fast(4, BatchCount::Four).estimate_cost_in_usd_cents(), 134);
assert_eq!(fast(5, BatchCount::Four).estimate_cost_in_usd_cents(), 168);
assert_eq!(fast(15, BatchCount::Four).estimate_cost_in_usd_cents(), 504);
}
}
fn test_session() -> AnyhowResult<Seedance2ProSession> {