vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use vyre::ops::encode::base64_encode::base64_encode;

#[test]
fn test_base64_encode_normal_cases() {
    let cases = vec![
        (b"Hello".as_ref(), b"SGVsbG8=".as_ref()),
        (b"Hello World", b"SGVsbG8gV29ybGQ="),
        (b"vyre", b"dnlyZQ=="),
        (b"a", b"YQ=="),
        (b"ab", b"YWI="),
        (b"abc", b"YWJj"),
    ];

    for (input, expected) in cases {
        let result = base64_encode(input);
        assert_eq!(
            result, expected,
            "Failed normal encode for input: {:?} (expected: {:?}, got: {:?})",
            input, expected, result
        );
    }
}

#[test]
fn test_base64_encode_boundary_empty() {
    let result = base64_encode(b"");
    assert_eq!(
        result, b"",
        "Failed empty buffer encode, expected empty byte array, got: {:?}",
        result
    );
}

#[test]
fn test_base64_encode_boundary_single_element() {
    let result = base64_encode(&[0]);
    assert_eq!(
        result, b"AA==",
        "Failed single zero byte encode, expected AA==, got: {:?}",
        result
    );

    let result_max = base64_encode(&[255]);
    assert_eq!(
        result_max, b"/w==",
        "Failed single 255 byte encode, expected /w==, got: {:?}",
        result_max
    );
}

#[test]
fn test_base64_encode_adversarial_large_input() {
    // Large input: 10,000 'A' characters
    let input = vec![b'A'; 10000];
    let result = base64_encode(&input);

    // We don't check the exact string here since it's large, but we check:
    // 1. Expected length: 10000 / 3 = 3333.33 -> 3334 chunks of 4 = 13336
    assert_eq!(
        result.len(),
        13336,
        "Failed large input length check, expected 13336, got: {}",
        result.len()
    );

    // 2. Starts with QUFR (encoding of AAA)
    assert_eq!(
        &result[0..4],
        b"QUFR",
        "Failed large input content check, expected QUFR at start, got: {:?}",
        &result[0..4]
    );

    // 3. Check correct padding, for 10000 % 3 = 1 remainder. So it has two '=' padding chars.
    assert_eq!(
        &result[result.len() - 2..],
        b"==",
        "Failed large input padding check, expected == at end, got: {:?}",
        &result[result.len() - 2..]
    );
}

#[test]
fn test_base64_encode_adversarial_all_possible_bytes() {
    let mut input = Vec::with_capacity(256);
    for i in 0..=255 {
        input.push(i as u8);
    }
    let result = base64_encode(&input);

    // Length check: ceil(256 / 3) * 4 = 86 * 4 = 344
    assert_eq!(
        result.len(),
        344,
        "Failed all-bytes encode length check, expected 344, got: {}",
        result.len()
    );

    // Ensure the output only contains valid base64 characters
    for &byte in &result {
        let is_valid = byte.is_ascii_alphanumeric() || byte == b'+' || byte == b'/' || byte == b'=';
        assert!(
            is_valid,
            "Output contains invalid base64 character: {}",
            byte as char
        );
    }
}