<commit_before>//
//  yas_audio_node_tests.m
//

#import "yas_audio_test_utils.h"

using namespace yas;

@interface yas_audio_node_tests : XCTestCase

@end

@implementation yas_audio_node_tests

- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

- (void)test_create_audio_node {
    test::audio_test_node node;

    XCTAssertEqual(node.input_bus_count(), 2);
    XCTAssertEqual(node.output_bus_count(), 1);

    XCTAssertEqual(node.manageable_node().input_connections().size(), 0);
    XCTAssertEqual(node.manageable_node().output_connections().size(), 0);
    XCTAssertEqual(*node.next_available_input_bus(), 0);
    XCTAssertEqual(*node.next_available_output_bus(), 0);
}

- (void)test_connection {
    test::audio_test_node source_node;
    test::audio_test_node destination_node;
    auto format = audio::format(44100.0, 2);
    auto source_bus_result = source_node.next_available_input_bus();
    auto destination_bus_result = destination_node.next_available_output_bus();

    XCTAssertTrue(source_bus_result);
    auto source_bus = *source_bus_result;
    XCTAssertEqual(source_bus, 0);

    XCTAssertTrue(destination_bus_result);
    auto destination_bus = *destination_bus_result;
    XCTAssertEqual(destination_bus, 0);

    if (auto connection = audio::connection::private_access::create(source_node, source_bus, destination_node,
                                                                    destination_bus, format)) {
        XCTAssertEqual(source_node.manageable_node().output_connections().size(), 1);
        XCTAssertEqual(destination_node.manageable_node().input_connections().size(), 1);
        XCTAssertEqual(source_node.manageable_node().output_connection(source_bus), connection);
        XCTAssertEqual(destination_node.manageable_node().input_connection(destination_bus), connection);
        XCTAssertEqual(source_node.output_format(source_bus), format);
        XCTAssertEqual(destination_node.input_format(destination_bus), format);

        XCTAssertFalse(source_node.output_format(source_bus + 1));
        XCTAssertFalse(destination_node.input_format(destination_bus + 1));

        XCTAssertFalse(source_node.next_available_output_bus());
        XCTAssertTrue(destination_node.next_available_input_bus());
        destination_bus_result = destination_node.next_available_input_bus();
        XCTAssertEqual(*destination_bus_result, 1);
    }

    source_bus_result = source_node.next_available_output_bus();
    destination_bus_result = destination_node.next_available_input_bus();
    XCTAssertEqual(*source_bus_result, 0);
    XCTAssertEqual(*destination_bus_result, 0);
}

- (void)test_reset {
    test::audio_test_node source_node;
    test::audio_test_node destination_node;
    auto format = audio::format(48000.0, 2);
    auto source_bus = *source_node.next_available_output_bus();
    auto destination_bus = *destination_node.next_available_input_bus();

    auto connection =
        audio::connection::private_access::create(source_node, source_bus, destination_node, destination_bus, format);

    XCTAssertEqual(source_node.manageable_node().output_connections().size(), 1);
    XCTAssertEqual(destination_node.manageable_node().input_connections().size(), 1);

    source_node.reset();
    XCTAssertEqual(source_node.manageable_node().output_connections().size(), 0);

    destination_node.reset();
    XCTAssertEqual(destination_node.manageable_node().input_connections().size(), 0);
}

- (void)test_render_time {
    auto node = audio::node::private_access::create();
    audio::time time(100, 48000.0);

    XCTestExpectation *render_expectation = [self expectationWithDescription:@"node render"];

    auto lambda = [self, node, time, render_expectation]() mutable {
        audio::pcm_buffer null_buffer;
        node.render(null_buffer, 0, time);
        [render_expectation fulfill];
    };

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), lambda);

    [self waitForExpectationsWithTimeout:1.0
                                 handler:^(NSError *error){

                                 }];<commit_msg>fix test<commit_after>//
//  yas_audio_node_tests.m
//

#import "yas_audio_test_utils.h"

using namespace yas;

@interface yas_audio_node_tests : XCTestCase

@end

@implementation yas_audio_node_tests

- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

- (void)test_create_audio_node {
    test::audio_test_node node;

    XCTAssertEqual(node.input_bus_count(), 2);
    XCTAssertEqual(node.output_bus_count(), 1);

    XCTAssertEqual(node.manageable_node().input_connections().size(), 0);
    XCTAssertEqual(node.manageable_node().output_connections().size(), 0);
    XCTAssertEqual(*node.next_available_input_bus(), 0);
    XCTAssertEqual(*node.next_available_output_bus(), 0);
}

- (void)test_connection {
    test::audio_test_node source_node;
    test::audio_test_node destination_node;
    auto format = audio::format(44100.0, 2);
    auto source_bus_result = source_node.next_available_input_bus();
    auto destination_bus_result = destination_node.next_available_output_bus();

    XCTAssertTrue(source_bus_result);
    auto source_bus = *source_bus_result;
    XCTAssertEqual(source_bus, 0);

    XCTAssertTrue(destination_bus_result);
    auto destination_bus = *destination_bus_result;
    XCTAssertEqual(destination_bus, 0);

    if (auto connection = audio::connection::private_access::create(source_node, source_bus, destination_node,
                                                                    destination_bus, format)) {
        XCTAssertEqual(source_node.manageable_node().output_connections().size(), 1);
        XCTAssertEqual(destination_node.manageable_node().input_connections().size(), 1);
        XCTAssertEqual(source_node.manageable_node().output_connection(source_bus), connection);
        XCTAssertEqual(destination_node.manageable_node().input_connection(destination_bus), connection);
        XCTAssertEqual(source_node.output_format(source_bus), format);
        XCTAssertEqual(destination_node.input_format(destination_bus), format);

        XCTAssertFalse(source_node.output_format(source_bus + 1));
        XCTAssertFalse(destination_node.input_format(destination_bus + 1));

        XCTAssertFalse(source_node.next_available_output_bus());
        XCTAssertTrue(destination_node.next_available_input_bus());
        destination_bus_result = destination_node.next_available_input_bus();
        XCTAssertEqual(*destination_bus_result, 1);
    }

    source_bus_result = source_node.next_available_output_bus();
    destination_bus_result = destination_node.next_available_input_bus();
    XCTAssertEqual(*source_bus_result, 0);
    XCTAssertEqual(*destination_bus_result, 0);
}

- (void)test_reset {
    test::audio_test_node source_node;
    test::audio_test_node destination_node;
    auto format = audio::format(48000.0, 2);
    auto source_bus = *source_node.next_available_output_bus();
    auto destination_bus = *destination_node.next_available_input_bus();

    auto connection =
        audio::connection::private_access::create(source_node, source_bus, destination_node, destination_bus, format);

    XCTAssertEqual(source_node.manageable_node().output_connections().size(), 1);
    XCTAssertEqual(destination_node.manageable_node().input_connections().size(), 1);

    source_node.reset();
    XCTAssertEqual(source_node.manageable_node().output_connections().size(), 0);

    destination_node.reset();
    XCTAssertEqual(destination_node.manageable_node().input_connections().size(), 0);
}

- (void)test_render_time {
    auto node = audio::node::private_access::create();
    audio::time time(100, 48000.0);

    XCTestExpectation *render_expectation = [self expectationWithDescription:@"node render"];

    auto lambda = [self, node, time, render_expectation]() mutable {
        audio::pcm_buffer null_buffer{nullptr};
        node.render(null_buffer, 0, time);
        [render_expectation fulfill];
    };

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), lambda);

    [self waitForExpectationsWithTimeout:1.0
                                 handler:^(NSError *error){

                                 }];
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.011135318324860808, 'mean_word_length': 4.553091397849462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2769328', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2458, 'n_words': 329}