mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
Extracts all public unittests from libphobos/src and emits them as standalone tests in the testsuite using the tests_extractor script. Compiling every module in the Phobos library with unittests included is computationally expensive, and these tests are now only ran when GCC_TEST_RUN_EXPENSIVE is not empty. When instead just compiling the unittests and linking in the module under test, this has been observed to reduce the time spent running the testsuite by more than half. libphobos/ChangeLog: * testsuite/libphobos.phobos/shared/phobos-shared.exp: Require is-effective-target run_expensive_tests. * testsuite/libphobos.phobos/static/phobos-static.exp: Likewise. * testsuite/libphobos.phobos/phobos.exp: New test. * testsuite/libphobos.phobos/std_algorithm_comparison.d: New test. * testsuite/libphobos.phobos/std_algorithm_iteration.d: New test. * testsuite/libphobos.phobos/std_algorithm_mutation.d: New test. * testsuite/libphobos.phobos/std_algorithm_searching.d: New test. * testsuite/libphobos.phobos/std_algorithm_setops.d: New test. * testsuite/libphobos.phobos/std_algorithm_sorting.d: New test. * testsuite/libphobos.phobos/std_array.d: New test. * testsuite/libphobos.phobos/std_ascii.d: New test. * testsuite/libphobos.phobos/std_base64.d: New test. * testsuite/libphobos.phobos/std_bigint.d: New test. * testsuite/libphobos.phobos/std_bitmanip.d: New test. * testsuite/libphobos.phobos/std_checkedint.d: New test. * testsuite/libphobos.phobos/std_complex.d: New test. * testsuite/libphobos.phobos/std_concurrency.d: New test. * testsuite/libphobos.phobos/std_container_array.d: New test. * testsuite/libphobos.phobos/std_container_binaryheap.d: New test. * testsuite/libphobos.phobos/std_container_dlist.d: New test. * testsuite/libphobos.phobos/std_container_rbtree.d: New test. * testsuite/libphobos.phobos/std_container_slist.d: New test. * testsuite/libphobos.phobos/std_container_util.d: New test. * testsuite/libphobos.phobos/std_conv.d: New test. * testsuite/libphobos.phobos/std_csv.d: New test. * testsuite/libphobos.phobos/std_datetime_date.d: New test. * testsuite/libphobos.phobos/std_datetime_interval.d: New test. * testsuite/libphobos.phobos/std_datetime_package.d: New test. * testsuite/libphobos.phobos/std_datetime_stopwatch.d: New test. * testsuite/libphobos.phobos/std_datetime_systime.d: New test. * testsuite/libphobos.phobos/std_datetime_timezone.d: New test. * testsuite/libphobos.phobos/std_demangle.d: New test. * testsuite/libphobos.phobos/std_digest_crc.d: New test. * testsuite/libphobos.phobos/std_digest_hmac.d: New test. * testsuite/libphobos.phobos/std_digest_md.d: New test. * testsuite/libphobos.phobos/std_digest_murmurhash.d: New test. * testsuite/libphobos.phobos/std_digest_package.d: New test. * testsuite/libphobos.phobos/std_digest_ripemd.d: New test. * testsuite/libphobos.phobos/std_digest_sha.d: New test. * testsuite/libphobos.phobos/std_encoding.d: New test. * testsuite/libphobos.phobos/std_exception.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_affix_allocator.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_aligned_block_list.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_allocator_list.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_ascending_page_allocator.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_bitmapped_block.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_bucketizer.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_fallback_allocator.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_free_list.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_kernighan_ritchie.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_quantizer.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_region.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_scoped_allocator.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_segregator.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_building_blocks_stats_collector.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_common.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_gc_allocator.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_mallocator.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_package.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_showcase.d: New test. * testsuite/libphobos.phobos/std_experimental_allocator_typed.d: New test. * testsuite/libphobos.phobos/std_file.d: New test. * testsuite/libphobos.phobos/std_format_package.d: New test. * testsuite/libphobos.phobos/std_format_read.d: New test. * testsuite/libphobos.phobos/std_format_spec.d: New test. * testsuite/libphobos.phobos/std_format_write.d: New test. * testsuite/libphobos.phobos/std_functional.d: New test. * testsuite/libphobos.phobos/std_getopt.d: New test. * testsuite/libphobos.phobos/std_int128.d: New test. * testsuite/libphobos.phobos/std_internal_cstring.d: New test. * testsuite/libphobos.phobos/std_internal_scopebuffer.d: New test. * testsuite/libphobos.phobos/std_json.d: New test. * testsuite/libphobos.phobos/std_logger_core.d: New test. * testsuite/libphobos.phobos/std_logger_nulllogger.d: New test. * testsuite/libphobos.phobos/std_math_algebraic.d: New test. * testsuite/libphobos.phobos/std_math_exponential.d: New test. * testsuite/libphobos.phobos/std_math_hardware.d: New test. * testsuite/libphobos.phobos/std_math_operations.d: New test. * testsuite/libphobos.phobos/std_math_remainder.d: New test. * testsuite/libphobos.phobos/std_math_rounding.d: New test. * testsuite/libphobos.phobos/std_math_traits.d: New test. * testsuite/libphobos.phobos/std_math_trigonometry.d: New test. * testsuite/libphobos.phobos/std_meta.d: New test. * testsuite/libphobos.phobos/std_mmfile.d: New test. * testsuite/libphobos.phobos/std_numeric.d: New test. * testsuite/libphobos.phobos/std_outbuffer.d: New test. * testsuite/libphobos.phobos/std_package.d: New test. * testsuite/libphobos.phobos/std_parallelism.d: New test. * testsuite/libphobos.phobos/std_path.d: New test. * testsuite/libphobos.phobos/std_random.d: New test. * testsuite/libphobos.phobos/std_range_interfaces.d: New test. * testsuite/libphobos.phobos/std_range_package.d: New test. * testsuite/libphobos.phobos/std_range_primitives.d: New test. * testsuite/libphobos.phobos/std_regex_package.d: New test. * testsuite/libphobos.phobos/std_signals.d: New test. * testsuite/libphobos.phobos/std_socket.d: New test. * testsuite/libphobos.phobos/std_stdio.d: New test. * testsuite/libphobos.phobos/std_string.d: New test. * testsuite/libphobos.phobos/std_sumtype.d: New test. * testsuite/libphobos.phobos/std_traits.d: New test. * testsuite/libphobos.phobos/std_typecons.d: New test. * testsuite/libphobos.phobos/std_typetuple.d: New test. * testsuite/libphobos.phobos/std_uni_package.d: New test. * testsuite/libphobos.phobos/std_uri.d: New test. * testsuite/libphobos.phobos/std_utf.d: New test. * testsuite/libphobos.phobos/std_uuid.d: New test. * testsuite/libphobos.phobos/std_variant.d: New test. * testsuite/libphobos.phobos/std_zlib.d: New test.
103 lines
2.7 KiB
D
103 lines
2.7 KiB
D
@system unittest
|
|
{
|
|
import std.container.binaryheap;
|
|
|
|
import std.algorithm.comparison : equal;
|
|
import std.range : take;
|
|
auto maxHeap = heapify([4, 7, 3, 1, 5]);
|
|
assert(maxHeap.take(3).equal([7, 5, 4]));
|
|
|
|
auto minHeap = heapify!"a > b"([4, 7, 3, 1, 5]);
|
|
assert(minHeap.take(3).equal([1, 3, 4]));
|
|
}
|
|
|
|
@system unittest
|
|
{
|
|
import std.container.binaryheap;
|
|
|
|
import std.algorithm.comparison : equal;
|
|
int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
|
|
auto h = heapify(a);
|
|
// largest element
|
|
assert(h.front == 16);
|
|
// a has the heap property
|
|
assert(equal(a, [ 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 ]));
|
|
}
|
|
|
|
@system unittest
|
|
{
|
|
import std.container.binaryheap;
|
|
|
|
import std.algorithm.comparison : equal;
|
|
import std.range : take;
|
|
int[] a = [4, 1, 3, 2, 16, 9, 10, 14, 8, 7];
|
|
auto top5 = heapify(a).take(5);
|
|
assert(top5.equal([16, 14, 10, 9, 8]));
|
|
}
|
|
|
|
@system unittest
|
|
{
|
|
import std.container.binaryheap;
|
|
|
|
import std.conv : to;
|
|
import std.range.primitives;
|
|
{
|
|
// example from "Introduction to Algorithms" Cormen et al., p 146
|
|
int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
|
|
auto h = heapify(a);
|
|
h = heapify!"a < b"(a);
|
|
assert(h.front == 16);
|
|
assert(a == [ 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 ]);
|
|
auto witness = [ 16, 14, 10, 9, 8, 7, 4, 3, 2, 1 ];
|
|
for (; !h.empty; h.removeFront(), witness.popFront())
|
|
{
|
|
assert(!witness.empty);
|
|
assert(witness.front == h.front);
|
|
}
|
|
assert(witness.empty);
|
|
}
|
|
{
|
|
int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
|
|
int[] b = new int[a.length];
|
|
BinaryHeap!(int[]) h = BinaryHeap!(int[])(b, 0);
|
|
foreach (e; a)
|
|
{
|
|
h.insert(e);
|
|
}
|
|
assert(b == [ 16, 14, 10, 8, 7, 3, 9, 1, 4, 2 ], to!string(b));
|
|
}
|
|
}
|
|
|
|
@system unittest
|
|
{
|
|
import std.container.binaryheap;
|
|
|
|
import std.stdio;
|
|
import std.algorithm.comparison : equal;
|
|
import std.container.binaryheap;
|
|
|
|
int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
|
|
auto h = heapify(a);
|
|
|
|
// Internal representation of Binary Heap tree
|
|
assert(a.equal([16, 14, 10, 8, 7, 9, 3, 2, 4, 1]));
|
|
|
|
h.replaceFront(30);
|
|
// Value 16 was replaced by 30
|
|
assert(a.equal([30, 14, 10, 8, 7, 9, 3, 2, 4, 1]));
|
|
|
|
// Making changes to the Store will be seen in the Heap
|
|
a[0] = 40;
|
|
assert(h.front() == 40);
|
|
|
|
// Inserting a new element will reallocate the Store, leaving
|
|
// the original Store unchanged.
|
|
h.insert(20);
|
|
assert(a.equal([40, 14, 10, 8, 7, 9, 3, 2, 4, 1]));
|
|
|
|
// Making changes to the original Store will not affect the Heap anymore
|
|
a[0] = 60;
|
|
assert(h.front() == 40);
|
|
}
|
|
|