unit uETLtests; interface uses System.Generics.Collections, DUnitX.TestFramework; type [TestFixture] testETL = class(TObject) private procedure CompareDictionaries(Expected, Actual: TDictionary); public [Test] procedure Validate_CompareDictionaries; [Test] // [Ignore] procedure Transforms_one_value; [Test] [Ignore] procedure Transforms_multiple_values; [Test] [Ignore] procedure Transforms_multiple_keys; [Test] [Ignore] procedure Transforms_a_full_dataset; end; implementation uses SysUtils, uETL; procedure testETL.CompareDictionaries(Expected, Actual: TDictionary); var expectedPair: TPair; begin Assert.AreEqual(Expected.Count, Actual.Count); for expectedPair in Expected do begin Assert.IsTrue(Actual.ContainsKey(expectedPair.Key)); Assert.AreEqual(expectedPair.Value, Actual[expectedPair.Key]); end; end; procedure testETL.Validate_CompareDictionaries; var expected, actual: TDictionary; begin expected := TDictionary.Create; expected.Add('r',5); expected.Add('a',10); expected.Add('n',15); expected.Add('d',20); expected.Add('o',25); expected.Add('m',30); actual := TDictionary.create(expected); CompareDictionaries(expected, actual); end; procedure testETL.Transforms_one_value; var aList: TList; old: TDictionary>; expected: TDictionary; begin aList := TList.Create; aList.Add('A'); old := TDictionary>.Create; old.Add(1, aList); expected := TDictionary.Create; expected.Add('a', 1); CompareDictionaries(expected, ETL.Transform(old)); end; procedure testETL.Transforms_multiple_values; var aList: TList; old: TDictionary>; expected: TDictionary; begin aList := TList.create; aList.AddRange(['A','E','I','O','U']); old := TDictionary>.Create; old.Add(1, aList); expected := TDictionary.Create; expected.Add('a',1); expected.Add('e',1); expected.Add('i',1); expected.Add('o',1); expected.Add('u',1); CompareDictionaries(expected, ETL.Transform(old)); end; procedure testETL.Transforms_multiple_keys; var aList: TList; old: TDictionary>; expected: TDictionary; begin aList := TList.Create; aList.Add('A'); aList.Add('E'); old := TDictionary>.Create; old.Add(1, aList); aList := TList.Create; aList.Add('D'); aList.Add('G'); old.Add(2, aList); expected := TDictionary.Create; expected.Add('a',1); expected.Add('e',1); expected.Add('d',2); expected.Add('g',2); CompareDictionaries(expected, ETL.Transform(old)); end; procedure testETL.Transforms_a_full_dataset; var aList: TList; old: TDictionary>; expected: TDictionary; begin aList := TList.Create; aList.AddRange(['A','E','I','O','U','L','N','R','S','T']); old := TDictionary>.Create; old.Add(1, aList); aList := TList.Create; aList.AddRange(['D','G']); old.Add(2, aList); aList := TList.Create; aList.AddRange(['B','C','M','P']); old.Add(3, aList); aList := TList.Create; aList.AddRange(['F','H','V','W','Y']); old.Add(4, aList); aList := TList.Create; aList.Add('K'); old.Add(5, aList); aList := TList.Create; aList.AddRange(['J','X']); old.Add(8, aList); aList := TList.Create; aList.AddRange(['Q','Z']); old.Add(10, aList); expected := TDictionary.Create; expected.Add('a',1); expected.Add('b',3); expected.Add('c',3); expected.Add('d',2); expected.Add('e',1); expected.Add('f',4); expected.Add('g',2); expected.Add('h',4); expected.Add('i',1); expected.Add('j',8); expected.Add('k',5); expected.Add('l',1); expected.Add('m',3); expected.Add('n',1); expected.Add('o',1); expected.Add('p',3); expected.Add('q',10); expected.Add('r',1); expected.Add('s',1); expected.Add('t',1); expected.Add('u',1); expected.Add('v',4); expected.Add('w',4); expected.Add('x',8); expected.Add('y',4); expected.Add('z',10); CompareDictionaries(expected, ETL.Transform(old)); end; initialization TDUnitX.RegisterTestFixture(testETL); end.