github.com/charypar/monobuild@v0.0.0-20211122220434-fd884ed50212/graph/print_test.go (about)

     1  package graph
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  var exampleDependencies = New(map[string][]Edge{
     8  	"a": []Edge{{Label: "c", Colour: Weak}, {Label: "b", Colour: Weak}},
     9  	"b": []Edge{{Label: "c", Colour: Weak}},
    10  	"c": []Edge{},
    11  	"d": []Edge{{Label: "a", Colour: Strong}},
    12  	"e": []Edge{{Label: "b", Colour: Strong}, {Label: "a", Colour: Strong}},
    13  })
    14  
    15  func TestText(t *testing.T) {
    16  	tests := []struct {
    17  		name      string
    18  		graph     Graph
    19  		selection []string
    20  		showType  bool
    21  		want      string
    22  	}{
    23  		{
    24  			"prints an empty graph",
    25  			exampleDependencies,
    26  			[]string{},
    27  			false,
    28  			"",
    29  		},
    30  		{
    31  			"prints a single node",
    32  			exampleDependencies,
    33  			[]string{"a"},
    34  			false,
    35  			"a: \n",
    36  		},
    37  		{
    38  			"prints a single edge",
    39  			exampleDependencies,
    40  			[]string{"a", "b"},
    41  			false,
    42  			"a: b\nb: \n",
    43  		},
    44  		{
    45  			"prints a fan",
    46  			exampleDependencies,
    47  			[]string{"a", "b", "c"},
    48  			false,
    49  			"a: b, c\nb: c\nc: \n",
    50  		},
    51  		{
    52  			"prints a graph",
    53  			exampleDependencies,
    54  			[]string{"a", "b", "c", "d"},
    55  			false,
    56  			"a: b, c\nb: c\nc: \nd: a\n",
    57  		},
    58  		{
    59  			"prints a graph with strength shown",
    60  			exampleDependencies,
    61  			[]string{"a", "b", "c", "d"},
    62  			true,
    63  			"a: b, c\nb: c\nc: \nd: !a\n",
    64  		},
    65  	}
    66  	for _, tt := range tests {
    67  		t.Run(tt.name, func(t *testing.T) {
    68  			if got := tt.graph.Text(tt.selection, tt.showType); got != tt.want {
    69  				t.Errorf("Text() = %v, want %v", got, tt.want)
    70  			}
    71  		})
    72  	}
    73  }
    74  
    75  func TestDot(t *testing.T) {
    76  	tests := []struct {
    77  		name      string
    78  		graph     Graph
    79  		selection []string
    80  		want      string
    81  	}{
    82  		{
    83  			"prints an empty graph",
    84  			exampleDependencies,
    85  			[]string{},
    86  			`digraph dependencies {
    87  }
    88  `,
    89  		},
    90  		{
    91  			"prints a single node",
    92  			exampleDependencies,
    93  			[]string{"a"},
    94  			`digraph dependencies {
    95    "a"
    96  }
    97  `,
    98  		},
    99  		{
   100  			"prints a single edge",
   101  			exampleDependencies,
   102  			[]string{"a", "b"},
   103  			`digraph dependencies {
   104    "a" -> "b" [style=dashed]
   105    "b"
   106  }
   107  `,
   108  		},
   109  		{
   110  			"prints a single strong edge",
   111  			exampleDependencies,
   112  			[]string{"a", "d"},
   113  			`digraph dependencies {
   114    "a"
   115    "d" -> "a"
   116  }
   117  `,
   118  		},
   119  		{
   120  			"prints a graph",
   121  			exampleDependencies,
   122  			[]string{"a", "b", "c", "d"},
   123  			`digraph dependencies {
   124    "a" -> "b" [style=dashed]
   125    "a" -> "c" [style=dashed]
   126    "b" -> "c" [style=dashed]
   127    "c"
   128    "d" -> "a"
   129  }
   130  `,
   131  		},
   132  	}
   133  	for _, tt := range tests {
   134  		t.Run(tt.name, func(t *testing.T) {
   135  			if got := tt.graph.Dot(tt.selection); got != tt.want {
   136  				t.Errorf("Dot() = %v, want %v", got, tt.want)
   137  			}
   138  		})
   139  	}
   140  }
   141  
   142  func TestDotSchedule(t *testing.T) {
   143  	tests := []struct {
   144  		name      string
   145  		graph     Graph
   146  		selection []string
   147  		want      string
   148  	}{
   149  		// TODO: Add test cases.
   150  	}
   151  	for _, tt := range tests {
   152  		t.Run(tt.name, func(t *testing.T) {
   153  			if got := tt.graph.DotSchedule(tt.selection); got != tt.want {
   154  				t.Errorf("DotSchedule() = %v, want %v", got, tt.want)
   155  			}
   156  		})
   157  	}
   158  }