Sha256: 4edd09cff78b71c18e6eda56f9004c670e7b6f34c6c1e3f97e551b3f6d6b49eb

Contents?: true

Size: 1.66 KB

Versions: 213

Compression:

Stored size: 1.66 KB

Contents

module etl;

import std.array : array;
import std.algorithm.sorting : sort;
import std.algorithm.comparison : equal;

unittest
{

// test associative array equality
bool aaEqual (const int[dchar] lhs, const int[dchar] rhs)
{
	auto lhs_pairs = lhs.byKeyValue.array;
	auto rhs_pairs = rhs.byKeyValue.array;
	lhs_pairs.sort!(q{a.key < b.key});
	rhs_pairs.sort!(q{a.key < b.key});

	return equal!("a.key == b.key && a.value == b.value")(lhs_pairs, rhs_pairs);
}

immutable int allTestsEnabled = 0;

// transform one value
{
	immutable string[int] old = [1: "A"];

	const auto actual = transform(old);
	const int[dchar] expected = ['a': 1];

	assert(aaEqual(expected, actual));
}

static if (allTestsEnabled)
{
// transform more values
{
	immutable string[int] old = [1: "AEIOU"];

	const auto actual = transform(old);
	const int[dchar] expected = ['a': 1, 'e': 1, 'i': 1, 'o': 1, 'u': 1];

	assert(aaEqual(expected, actual));
}

// transforms more keys
{
	immutable string[int] old = [1: "AE", 2: "DG"];

	const auto actual = transform(old);
	const int[dchar] expected = ['a': 1, 'e': 1, 'd': 2, 'g': 2];

	assert(aaEqual(expected, actual));
}

// transforms a full dataset
{
	immutable string[int] old = [1: "AEIOULNRST",
								2: "DG",
								3: "BCMP",
								4: "FHVWY",
								5: "K",
								8: "JX",
								10: "QZ"];

	const auto actual = transform(old);

	const int[dchar] expected = ['a': 1, 'b': 3,  'c': 3, 'd': 2, 'e': 1,
								'f': 4, 'g': 2,  'h': 4, 'i': 1, 'j': 8,
								'k': 5, 'l': 1,  'm': 3, 'n': 1, 'o': 1,
								'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1,
								'u': 1, 'v': 4,  'w': 4, 'x': 8, 'y': 4,
								'z': 10];

	assert(aaEqual(expected, actual));
}

}

}

Version data entries

213 entries across 213 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.138 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.137 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.136 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.135 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.134 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.133 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.132 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.131 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.130 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.129 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.128 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.127 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.126 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.125 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.124 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.123 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.122 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.121 tracks/d/exercises/etl/source/etl.d
trackler-2.2.1.120 tracks/d/exercises/etl/source/etl.d