Skip to content

Commit

Permalink
Merge pull request #112 from IntelliTect/03-Ranges
Browse files Browse the repository at this point in the history
Added Range listings.
  • Loading branch information
MarkMichaelis committed Oct 12, 2019
2 parents 5949671 + a9a3fd1 commit 1c0406c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/Chapter03.Tests/Listing03.26B.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ public class ProgramTests
public void Main_GetLengthOfDimensionOf3DArray_ReturnsLength()
{
const string expected =
@"TypeScript
Python";
@" 0..3: C#, COBOL, Java
^3..^0: Python, Lisp, JavaScript
3..^3: C++, TypeScript, Pascal
..^6: C#, COBOL, Java
6..: Python, Lisp, JavaScript
..: C#, COBOL, Java, C++, TypeScript, Pascal, Python, Lisp, JavaScript
..: C#, COBOL, Java, C++, TypeScript, Pascal, Python, Lisp, JavaScript";

IntelliTect.TestTools.Console.ConsoleAssert.Expect(
expected, Program.Main);
Expand Down
37 changes: 29 additions & 8 deletions src/Chapter03/Listing03.26B.Slicing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,35 @@ public static void Main()
"C#", "COBOL", "Java",
"C++", "TypeScript", "Pascal",
"Python", "Lisp", "JavaScript"};
// Retrieve fifth item in languages array (TypeScript)
string language = languages[4];
// Write “TypeScript”
System.Console.WriteLine(language);
// Retrieve second item from the end (Python)
language = languages[^3];
// Write “Python”
System.Console.WriteLine(language);

System.Console.WriteLine($@" 0..3: {
string.Join(", ", languages[0..3]) // C#, COBOL, Java
}");
System.Console.WriteLine($@"^3..^0: {
string.Join(", ", languages[^3..^0]) // Python, Lisp, JavaScript
}");
System.Console.WriteLine($@" 3..^3: {
string.Join(", ", languages[3..^3]) // C++, TypeScript, Pascal
}");
System.Console.WriteLine($@" ..^6: {
string.Join(", ", languages[..^6]) // C#, COBOL, Java
}");
System.Console.WriteLine($@" 6..: {
string.Join(", ", languages[6..]) // Python, Lisp, JavaScript
}");
System.Console.WriteLine($@" ..: {
// C#, COBOL, Java, C++, TypeScript, Pascal, Python, Lisp, JavaScript
string.Join(", ", languages[..]) // Python, Lisp, JavaScript
}");





System.Console.WriteLine($@" ..: {
// C#, COBOL, Java, C++, TypeScript, Pascal, Python, Lisp, JavaScript
string.Join(", ", languages[0..^0]) // Python, Lisp, JavaScript
}");
}
}
}

0 comments on commit 1c0406c

Please sign in to comment.