File: cartesian_product_test.cpp

package info (click to toggle)
cataclysm-dda 0.H-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 710,808 kB
  • sloc: cpp: 524,019; python: 11,580; sh: 1,228; makefile: 1,169; xml: 507; javascript: 150; sql: 56; exp: 41; perl: 37
file content (20 lines) | stat: -rw-r--r-- 825 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "cata_catch.h"

#include "cartesian_product.h"

TEST_CASE( "cartesian_product" )
{
    std::vector<int> empty;
    std::vector<int> singleton = { 0 };
    std::vector<int> pair = { 1, 2 };

    using Lists = std::vector<std::vector<int>>;

    CHECK( cata::cartesian_product( Lists{} ) == Lists{ {} } );
    CHECK( cata::cartesian_product( Lists{ empty } ).empty() );
    CHECK( cata::cartesian_product( Lists{ empty, singleton } ).empty() );
    CHECK( cata::cartesian_product( Lists{ empty, pair } ).empty() );
    CHECK( cata::cartesian_product( Lists{ singleton, singleton } ) == Lists{ { 0, 0 } } );
    CHECK( cata::cartesian_product( Lists{ singleton, pair } ) == Lists{ { 0, 1 }, { 0, 2 } } );
    CHECK( cata::cartesian_product( Lists{ pair, pair } ) == Lists{ { 1, 1 }, { 2, 1 }, { 1, 2 }, { 2, 2 } } );
}