/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/macros.internal.h" #include "libc/mem/alg.h" #include "libc/testlib/testlib.h" STATIC_YOINK("realloc"); TEST(tarjan, empty_doesNothing) { int sorted_vertices[1] = {-1}; int edges[][2] = {{0, 0}}; int vertex_count = 0; int edge_count = 0; _tarjan(vertex_count, (void *)edges, edge_count, sorted_vertices, NULL, NULL); ASSERT_EQ(-1, sorted_vertices[0]); } TEST(tarjan, topologicalSort_noCycles) { enum VertexIndex { A = 0, B = 1, C = 2, D = 3 }; const char *const vertices[] = {[A] = "A", [B] = "B", [C] = "C", [D] = "D"}; int edges[][2] = {{A /* depends on → */, B /* which must come before A */}, {A /* depends on → */, C /* which must come before A */}, {A /* depends on → */, D /* which must come before A */}, {B /* depends on → */, C /* which must come before B */}, {B /* depends on → */, D /* which must come before B */}}; /* $ tsort <