Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
IncrTopoSortTest.cpp File Reference
#include "include/core/SkRefCnt.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTDArray.h"
#include "src/base/SkTSort.h"
#include "tests/Test.h"
#include <algorithm>
#include <cstdint>

Go to the source code of this file.

Classes

class  Node
 
class  Graph
 

Functions

static void test_1 (skiatest::Reporter *reporter)
 
static void test_2 (skiatest::Reporter *reporter)
 
static void test_diamond (skiatest::Reporter *reporter)
 
static void test_lopsided_binary_tree (skiatest::Reporter *reporter)
 
 DEF_TEST (IncrTopoSort, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( IncrTopoSort  ,
reporter   
)

Definition at line 493 of file IncrTopoSortTest.cpp.

493 {
498}
reporter
static void test_2(skiatest::Reporter *reporter)
static void test_lopsided_binary_tree(skiatest::Reporter *reporter)
static void test_1(skiatest::Reporter *reporter)
static void test_diamond(skiatest::Reporter *reporter)

◆ test_1()

static void test_1 ( skiatest::Reporter reporter)
static

Definition at line 327 of file IncrTopoSortTest.cpp.

327 {
328 Graph g(10, reporter);
329
330 Node* nodeQ = g.addNode('q');
331 Node* nodeY = g.addNode('y');
332 Node* nodeA = g.addNode('a');
333 Node* nodeZ = g.addNode('z');
334 Node* nodeB = g.addNode('b');
335 /*Node* nodeC =*/ g.addNode('c');
336 Node* nodeW = g.addNode('w');
337 Node* nodeD = g.addNode('d');
338 Node* nodeX = g.addNode('x');
339 Node* nodeR = g.addNode('r');
340
341 // All these edge are non-invalidating
342 g.addEdge(nodeD, nodeR);
343 g.addEdge(nodeZ, nodeW);
344 g.addEdge(nodeA, nodeB);
345 g.addEdge(nodeY, nodeZ);
346 g.addEdge(nodeQ, nodeA);
347
348 {
349 const SkString kExpectedInitialState("q,y,a,z,b,c,w,d,x,r");
350 SkString actualInitialState;
351 g.getActual(&actualInitialState);
352 REPORTER_ASSERT(reporter, kExpectedInitialState == actualInitialState);
353 }
354
355 // Add the invalidating edge
356 g.addEdge(nodeX, nodeY);
357
358 {
359 const SkString kExpectedFinalState("q,a,b,c,d,x,y,z,w,r");
360 SkString actualFinalState;
361 g.getActual(&actualFinalState);
362 REPORTER_ASSERT(reporter, kExpectedFinalState == actualFinalState);
363 }
364}
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
Definition dart.idl:29

◆ test_2()

static void test_2 ( skiatest::Reporter reporter)
static

Definition at line 367 of file IncrTopoSortTest.cpp.

367 {
368 Graph g(10, reporter);
369
370 Node* nodeY = g.addNode('y');
371 /*Node* nodeA =*/ g.addNode('a');
372 Node* nodeW = g.addNode('w');
373 /*Node* nodeB =*/ g.addNode('b');
374 Node* nodeZ = g.addNode('z');
375 Node* nodeU = g.addNode('u');
376 /*Node* nodeC =*/ g.addNode('c');
377 Node* nodeX = g.addNode('x');
378 /*Node* nodeD =*/ g.addNode('d');
379 Node* nodeV = g.addNode('v');
380
381 // All these edge are non-invalidating
382 g.addEdge(nodeU, nodeX);
383 g.addEdge(nodeW, nodeU);
384 g.addEdge(nodeW, nodeZ);
385 g.addEdge(nodeY, nodeZ);
386
387 {
388 const SkString kExpectedInitialState("y,a,w,b,z,u,c,x,d,v");
389 SkString actualInitialState;
390 g.getActual(&actualInitialState);
391 REPORTER_ASSERT(reporter, kExpectedInitialState == actualInitialState);
392 }
393
394 // Add the first invalidating edge
395 g.addEdge(nodeX, nodeY);
396
397 {
398 const SkString kExpectedFirstState("a,w,b,u,c,x,y,z,d,v");
399 SkString actualFirstState;
400 g.getActual(&actualFirstState);
401 REPORTER_ASSERT(reporter, kExpectedFirstState == actualFirstState);
402 }
403
404 // Add the second invalidating edge
405 g.addEdge(nodeV, nodeW);
406
407 {
408 const SkString kExpectedSecondState("a,b,c,d,v,w,u,x,y,z");
409 SkString actualSecondState;
410 g.getActual(&actualSecondState);
411 REPORTER_ASSERT(reporter, kExpectedSecondState == actualSecondState);
412 }
413}

◆ test_diamond()

static void test_diamond ( skiatest::Reporter reporter)
static

Definition at line 415 of file IncrTopoSortTest.cpp.

415 {
416 Graph g(4, reporter);
417
418 /* Create the graph (the '.' is the pointy side of the arrow):
419 * b
420 * . \
421 * / .
422 * a d
423 * \ .
424 * . /
425 * c
426 * Possible topological orders are [a,c,b,d] and [a,b,c,d].
427 */
428
429 Node* nodeD = g.addNode('d');
430 Node* nodeC = g.addNode('c');
431 Node* nodeB = g.addNode('b');
432
433 {
434 SkTDArray<Node*> dependedOn;
435 dependedOn.push_back(nodeB);
436 dependedOn.push_back(nodeC);
437
438 g.addEdges(&dependedOn, nodeD); // nodes B and C must come before node D
439 }
440
441 Node* nodeA = g.addNode('a');
442 g.addEdge(nodeA, nodeB); // node A must come before node B
443 g.addEdge(nodeA, nodeC); // node A must come before node C
444
445 const SkString kExpected0("a,c,b,d");
446 const SkString kExpected1("a,b,c,d");
447 SkString actual;
448 g.getActual(&actual);
449
450 REPORTER_ASSERT(reporter, kExpected0 == actual || kExpected1 == actual);
451}
void push_back(const T &v)
Definition SkTDArray.h:219

◆ test_lopsided_binary_tree()

static void test_lopsided_binary_tree ( skiatest::Reporter reporter)
static

Definition at line 453 of file IncrTopoSortTest.cpp.

453 {
454 Graph g(7, reporter);
455
456 /* Create the graph (the '.' is the pointy side of the arrow):
457 * a
458 * / \
459 * . .
460 * b c
461 * / \
462 * . .
463 * d e
464 * / \
465 * . .
466 * f g
467 *
468 * Possible topological order is: [a,b,c,d,e,f,g].
469 */
470
471 Node* nodeG = g.addNode('g');
472 Node* nodeF = g.addNode('f');
473 Node* nodeE = g.addNode('e');
474 Node* nodeD = g.addNode('d');
475 Node* nodeC = g.addNode('c');
476 Node* nodeB = g.addNode('b');
477 Node* nodeA = g.addNode('a');
478
479 g.addEdge(nodeE, nodeG);
480 g.addEdge(nodeE, nodeF);
481 g.addEdge(nodeC, nodeE);
482 g.addEdge(nodeC, nodeD);
483 g.addEdge(nodeA, nodeC);
484 g.addEdge(nodeA, nodeB);
485
486 const SkString kExpected("a,b,c,d,e,f,g");
487 SkString actual;
488 g.getActual(&actual);
489
490 REPORTER_ASSERT(reporter, kExpected == actual);
491}