Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program FlatMapTests;
- uses
- TestFramework,
- TestInsight.DUnit,
- Spring.Collections,
- Spring.Collections.Extensions;
- type
- TDeveloper = class
- private
- fName: string;
- fLanguages: IList<string>;
- function GetLanguages: IEnumerable<string>;
- public
- constructor Create(const name: string);
- procedure Add(const language: string);
- property Languages: IEnumerable<string> read GetLanguages;
- end;
- TFlatMapTest = class(TTestCase)
- published
- procedure FlatMap;
- end;
- procedure TFlatMapTest.FlatMap;
- var
- team: IList<TDeveloper>;
- polyglot, busy: TDeveloper;
- teamLanguages: IEnumerable<string>;
- begin
- team := TCollections.CreateList<TDeveloper>(True);
- polyglot := TDeveloper.Create('esoteric');
- polyglot.Add('clojure');
- polyglot.Add('scala');
- polyglot.Add('groovy');
- polyglot.Add('go');
- busy := TDeveloper.Create('pragmatic');
- busy.Add('java');
- busy.Add('javascript');
- team.Add(polyglot);
- team.Add(busy);
- teamLanguages :=
- TSelectManyIterator<TDeveloper,string>.Create(team,
- function(d: TDeveloper): IEnumerable<string>
- begin
- Result := d.Languages
- end);
- Check(polyglot.Languages.All(function(const s: string): Boolean begin Result := teamLanguages.Contains(s) end));
- Check(busy.Languages.All(function(const s: string): Boolean begin Result := teamLanguages.Contains(s) end));
- teamLanguages := nil;
- end;
- constructor TDeveloper.Create(const name: string);
- begin
- inherited Create;
- fName := name;
- fLanguages := TCollections.CreateList<string>;
- end;
- procedure TDeveloper.Add(const language: string);
- begin
- fLanguages.Add(language);
- end;
- function TDeveloper.GetLanguages: IEnumerable<string>;
- begin
- Result := fLanguages;
- end;
- begin
- RegisterTest(TFlatMapTest.Suite);
- RunRegisteredTests;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement