public void Part2_WithSampleInput_ShouldReturn8() { string sampleInput = @"16 10 15 5 1 11 7 19 6 12 4"; string[] input = new List <string>( sampleInput.Split(Environment.NewLine, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries ) ) .ToArray(); List <int> joltageData = new List <int>(Array.ConvertAll(input, s => int.Parse(s))); joltageData.Add(0); joltageData.Add(joltageData.Max() + 3); AdapterChain adapters = new AdapterChain(joltageData); long total = adapters.CountCombinations(); Assert.Equal(8, total); }
public void Part1_WithSampleInput_ShouldReturn35() { string sampleInput = @"16 10 15 5 1 11 7 19 6 12 4"; string[] input = new List <string>( sampleInput.Split(Environment.NewLine, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries ) ) .ToArray(); List <int> joltageData = new List <int>(Array.ConvertAll(input, s => int.Parse(s))); joltageData.Add(0); joltageData.Add(joltageData.Max() + 3); AdapterChain adapters = new AdapterChain(joltageData); (int countOf1Diffs, int countOf3Diffs) = adapters.GetJoltageDiffs(); int product = countOf1Diffs * countOf3Diffs; Assert.Equal(35, product); }
public void AdaptStringTest() { var adapter = AdapterChain.Create(new CharSplitAdapter(split), new StringZipAdapter(Headers)); var result = adapter.Adapt(TestFirstString); Assert.AreEqual(ExpectedFirst, result); }
public IAdapter <string, T> Create(string headerString) { var headers = headerAdapter.Adapt(headerString); var stringToDictionaryAdapter = AdapterChain.Create(bodyAdapter, new StringZipAdapter(headers)); return(AdapterChain.Create(stringToDictionaryAdapter, objectAdapter)); }
public void Part1_WithSecondSampleInput_ShouldReturn220() { string sampleInput = @"28 33 18 42 31 14 46 20 48 47 24 23 49 45 19 38 39 11 1 32 25 35 8 17 7 9 4 2 34 10 3"; string[] input = new List <string>( sampleInput.Split(Environment.NewLine, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries ) ) .ToArray(); List <int> joltageData = new List <int>(Array.ConvertAll(input, s => int.Parse(s))); joltageData.Add(0); joltageData.Add(joltageData.Max() + 3); AdapterChain adapters = new AdapterChain(joltageData); (int countOf1Diffs, int countOf3Diffs) = adapters.GetJoltageDiffs(); int product = countOf1Diffs * countOf3Diffs; Assert.Equal(220, product); }
public void Part2_WithSecondSampleInput_ShouldReturn19208() { string sampleInput = @"28 33 18 42 31 14 46 20 48 47 24 23 49 45 19 38 39 11 1 32 25 35 8 17 7 9 4 2 34 10 3"; string[] input = new List <string>( sampleInput.Split(Environment.NewLine, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries ) ) .ToArray(); List <int> joltageData = new List <int>(Array.ConvertAll(input, s => int.Parse(s))); joltageData.Add(0); joltageData.Add(joltageData.Max() + 3); AdapterChain adapters = new AdapterChain(joltageData); long total = adapters.CountCombinations(); Assert.Equal(19208, total); }
public void AdaptFileName() { var filePath = Path.GetFullPath("C:/a/long/path/to/pathfilename.txt"); var dateTimeProvider = new ConstantDateTimeProvider(new DateTime(2010, 1, 1, 13, 30, 30)); var adapter = AdapterChain.Create( new InsertPreExtensionTimestampFilePathAdapter(dateTimeProvider), new ReplaceInFileNameFilePathAdapter("path", "new"), new InsertPreExtensionFilePathAdapter("extra"), new AppendDirectoryFilePathAdapter("extend"), new ModifyExtensionFilePathAdapter("csv") ); // act var result = adapter.Adapt(filePath); // assert var expected = Path.GetFullPath("C:/a/long/path/to/extend/newfilename20100101133030000extra.csv"); Assert.AreEqual(expected, result); }
public void ParseStreamTest() { // arrange string TestString = TestFirstString + Environment.NewLine + TestSecondString; var adapter = AdapterChain.Create(new CharSplitAdapter(split), new StringZipAdapter(Headers)); List <IReadOnlyDictionary <string, string> > parsed = new List <IReadOnlyDictionary <string, string> >(); using (var s = new MemoryStream(Encoding.UTF8.GetBytes(TestString))) using (StreamReader sr = new StreamReader(s)) using (var stream = new LineReadStream(sr)) using (var adapterStream = new AdapterReadStream <string, IReadOnlyDictionary <string, string> >(adapter, stream)) { // act while (adapterStream.IsDataAvailable()) { parsed.Add(adapterStream.ReadFromStream()); } } // assert Assert.AreEqual(ExpectedFirst, parsed[0]); Assert.AreEqual(ExpectedSecond, parsed[1]); }
public IAdapter <string, IReadOnlyDictionary <string, string> > Create(string headerString) { var headers = headerAdapter.Adapt(headerString); return(AdapterChain.Create(bodyAdapter, new StringZipAdapter(headers))); }