HEX
Server: LiteSpeed
System: Linux br-asc-web1845.main-hosting.eu 5.14.0-611.42.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 24 05:30:20 EDT 2026 x86_64
User: u790421558 (790421558)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //proc/thread-self/root/opt/golang/1.22.0/src/internal/dag/alg_test.go
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dag

import (
	"reflect"
	"strings"
	"testing"
)

func TestTranspose(t *testing.T) {
	g := mustParse(t, diamond)
	g.Transpose()
	wantEdges(t, g, "a->b a->c a->d b->d c->d")
}

func TestTopo(t *testing.T) {
	g := mustParse(t, diamond)
	got := g.Topo()
	// "d" is the root, so it's first.
	//
	// "c" and "b" could be in either order, but Topo is
	// deterministic in reverse node definition order.
	//
	// "a" is a leaf.
	wantNodes := strings.Fields("d c b a")
	if !reflect.DeepEqual(wantNodes, got) {
		t.Fatalf("want topo sort %v, got %v", wantNodes, got)
	}
}

func TestTransitiveReduction(t *testing.T) {
	t.Run("diamond", func(t *testing.T) {
		g := mustParse(t, diamond)
		g.TransitiveReduction()
		wantEdges(t, g, "b->a c->a d->b d->c")
	})
	t.Run("chain", func(t *testing.T) {
		const chain = `NONE < a < b < c < d; a, d < e;`
		g := mustParse(t, chain)
		g.TransitiveReduction()
		wantEdges(t, g, "e->d d->c c->b b->a")
	})
}