NOTE: To add Advanced zyLabs your zyBook must have zyLabs enabled. If you'd like to enable (or are unsure if zyLabs is already enabled), contact your Account Executive.
Jump to:
Use Visual Studio in the Advanced zyLab
Getting Started
Advanced zyLabs can be added to any existing or new section. Start by expanding the chapter containing the section to add an Advanced zyLabs IDE. Expanding a chapter can be done in the table of contents on the zyBook homepage or in the content's sidebar.
Next, either click on an existing custom section, or click "Create section" at the bottom of the chapter.
Inside the section, click "Advanced zyLab" to add one to the page. Any number of labs can be added to a section.
You can also select "Import advanced lab" if you have an existing lab in another section that you'd like to copy into this one.
Next, select the language to use for this Advanced zyLab.
This may include the version of the language selected, as well as the option to use our CR2 IDE or the Visual Studio Code editor. Learn more about the VSC IDE by clicking here.
Hit "Create" to begin editing the template.
The Template for each Advanced zyLab is what learners will see when the page is published. It can be edited at any time, even after publishing. However, learners will need to "Reset to template" to see any changes if they opened the assignment before the template was edited.
IDE Menu
At the top left of the IDE is the IDE menu.
Files
Click the file tree icon to open the file tree to create files and folders, re-arrange files, as well as upload, download, rename, duplicate, and delete files.
The three-dot menu at the end of each file contains some of these options.
Settings
The settings menu provides options to change the default file, write a custom run config, or change the IDE language.
Event History
The event history will bring up a window that indicates changes made to the IDE or Files.
Run
Run will compile and run based on the default file, but a drop-down menu allows for selecting other files to run.
Desktop View
After running code in most languages, a new button will appear in the IDE that allows a desktop view. Some languages open this view by default.
Any code with visual output, from the HTML/CSS/JS output of a webpage, to the movement of the turtle in the example below can be seen by opening the desktop.
Depending on the language, there may be an option in the console to open that view in a new tab, or you can enlarge the desktop view like in the image above. The fullscreen or new tab icon, visible next to the audio toggle above, will also allow you to view this window fullscreen.
Playback
Between the File and Run button, is the Playback button.
Learner work can be checked keystroke-by-keystroke by clicking the forward and back arrows, or scrolling through the timeline just above the timestamp.
Playback view:
In the example above the IDE goes from empty, to the completed program in one keystroke. This all takes place in less than one minute.
Press the return arrow at any time to return to the code editor.
Other Icons
A number of other icons are visible across the IDE and noted in the image below.
1. Connection indicator and Presence Indicator
a. Indicates if you are online, and who else is currently connected to the IDE
2. Run Tests and Sync button
a. Click to run tests. See more info about the test bench in the next section
b. The Sync button indicates files are synced, and can be clicked to re-sync
3. Expand/Collapse bar
a. Click and drag to expand or collapse the bottom section of the IDE. These bars can be seen in other sections of the IDE as well, like the test bench
4. Console and Shell
a. Use the console to see output, enter input, and enter other commands
b. Use the shell to send commands for things like file management, process management, and environment variable management, especially when the console is busy
5. Reset Instance
a. Use this button to reset the instance if it becomes unresponsive, but keep in mind this can remove work if the IDE is in a disconnected state
Hotkeys
There are a number of Hotkeys and shortcuts that can be used inside the IDE.
F1
- Open Command Palette
Right-Click Menu includes useful hotkeys like these:Alt + Windows + N
- Run
Ctrl + F2
- Change All Occurrences
Shift+ Alt+ F
- Format Document (Auto-indent)
Ctrl + K
- Add Comment
Ctrl + F
- Find
Ctrl + G
- Go to line
Ctrl + ,
- Make Font Smaller
Ctrl + .
- Make Font Larger
Ctrl + Shift + Enter
- Insert Line Above
Ctrl + Enter
- Insert Line Below
Ctrl + Shift + K
- Delete Line
Ctrl + Shift + [
- Fold
Alt + F8
- Go to Next Problem (Error, Warning, Info)
Test Bench
The Test Bench is where autograded tests can be assigned. Just click "Add Test Case" to begin.
Next enter a title and point value for this test, then select a test type.
Feedback for a failed test can be entered, but this is not required.
The "Hidden" toggle will hide the results of this test but will still display the pass/fail and any feedback. In the example below the first test shows the results while the second is a hidden test.
Choosing the type of test to use depends on how the code should be evaluated. Input/Output can be best for code that produces uniform results, and when the functionality of the code is the most important factor. Unit tests are more complex, but allow for a more rigorous check of the methodology of the code. Bash tests can be easier to write than unit tests, and look primarily at the functionality of the code.
These tests types can be used in conjunction with each other.
Input/Output comparison tests
I/O tests include a selection for the method of comparison and fields to pass input into a learner's workspace and check their output. However, input is not required to create an I/O test.
The following Python code asks for input and then reports an output.
def color_temp(color):
# Check if the color input is in the list of warm colors
if color.lower() in ["red", "orange", "yellow"]:
return "Warm"
# Check if the color input is in the list of cold colors
elif color.lower() in ["blue", "green", "purple"]:
return "Cold"
# If the color is not in the list of warm or cold colors
else:
return "Invalid color"
# Prompt the user to input a primary color
user_color = input("Enter a primary color: ")
# Output the temperature classification of the color
print(color_temp(user_color))
An I/O test would send the applicable input color and the output would check against it.
Here are two possible I/O tests:
Input: black
Output: Enter a primary color:
Input: blue
Output: Cold
Unit tests
Unit tests will default to the most applicable testing framework for the language selected for the IDE. The dropdown allows changing the framework.
The unit test can be edited as needed, or a test can be uploaded and the default removed via the menu indicated in the image above. Other files can also be added or uploaded as well, like a data set to reference in the unit test.
The following C# code asks the user for four things and reports one thing in common. For this example, a unit test is a good solution for autograding.
using System;
class Program
{
static void Main()
{
string[] likes = new string[4];
for (int i = 0; i < 4; i++)
{
Console.Write("Enter thing number {0} that you like: ", i + 1);
likes[i] = Console.ReadLine();
}
Random rand = new Random();
int index = rand.Next(4);
Console.WriteLine("I also like {0}!", likes[index]);
}
}
See this article for more information about unit tests.
Custom bash tests
Custom bash tests allow you to write a shell script and define your own logic for passing/failing tests and assigning points. You can include special compile and run commands to test how code will behave in different circumstances. You can include additional files with the test and run whatever tools you need to evaluate student code.
Model Solution
Model solutions are a great way to verify the test bench works properly with an ideal solution. Click on the Model Solution tab, then "Create Model Solution" to begin.
A default model solution will be created based on the existing template. Click "Run Tests" to verify they work as expected.
Using GitHub with Advanced zyLabs
The git
command is useable in the Advanced zyLab IDE. It's also useable in VSC and includes a GUI there. Learn more about VSC and GitHub here.
While VSC is recommended, using git
commands from the CR2 console does allow push, pull, clone, and other actions once it's connected to your repositories.
Typing git help
in the console reveals the full list of commands.