Untitled
unknown
plain_text
6 months ago
7.2 kB
8
Indexable
import 'cypress-real-events/support';
const programGTurtleState =
'{"commands":[{"penState":{"imagePath":"app/img/turtles/turtle0.png","isPenDown":true,"isErasingOn":false,"isVisible":true,"penColor":"rgb(0,0,0)","fillColor":"rgb(0,0,0)","penWidth":1,"direction":0,"position":{"x":0,"y":0},"turtleWidth":51.6,"turtleHeight":59.6},"x":0,"y":0,"endX":0,"endY":-100}],"backgroundColor":"white","turtleState":{"imagePath":"app/img/turtles/turtle0.png","isPenDown":true,"isErasingOn":false,"isVisible":true,"penColor":"rgb(0,0,0)","fillColor":"rgb(0,0,0)","penWidth":1,"direction":0,"position":{"x":0,"y":-100},"turtleWidth":51.6,"turtleHeight":59.6}}';
const programGTurtle = `from gturtle import *
makeTurtle()
fd(100)
print(getY())`;
const programGTurtleOutput = ['-100'];
const programLog = `print(100)
print("text")`;
const programLogOutput = ['100', 'text'];
const programPrompt = `a = input("Enter test value")
print(a)
print(input())`;
const programPromptOutput = ['18', '18'];
const programNumpy = `import numpy as np
print(np.zeros(3))`;
const programNumpyOutput = ['[0. 0. 0.]'];
const programIntegrated = `from gturtle import *
makeTurtle()
fd(100)
print(getY())
a = input("Wert eingeben")
print(a)
import numpy as np
print(np.zeros(3))
repeat a:
fd(25)
rt(20)`;
const programIntegratedOutput = ['-100', '18', '[0. 0. 0.]'];
const _progrmIntegratedState =
'{"commands":[{"penState":{"imagePath":"app/img/turtles/turtle0.png","isPenDown":true,"isErasingOn":false,"isVisible":true,"penColor":"rgb(0,0,0)","fillColor":"rgb(0,0,0)","penWidth":1,"direction":0,"position":{"x":0,"y":0},"turtleWidth":51.6,"turtleHeight":59.6},"x":0,"y":0,"endX":0,"endY":-100}],"backgroundColor":"white","turtleState":{"imagePath":"app/img/turtles/turtle0.png","isPenDown":true,"isErasingOn":false,"isVisible":true,"penColor":"rgb(0,0,0)","fillColor":"rgb(0,0,0)","penWidth":1,"direction":0,"position":{"x":0,"y":-100},"turtleWidth":51.6,"turtleHeight":59.6}}';
const programSpeedSlider = `from gturtle import *
makeTurtle()
repeat 360:
fd(1)
rt(1)`;
describe('Using the mega stage for writing python code.', () => {
beforeEach(() => {
cy.visit('/#/mega');
// clear the editor content
cy.get('.ace_editor')
.should('be.visible')
.click()
.focused()
.then(() => {
const isMac = Cypress.platform === 'darwin';
const modifier = isMac ? 'Meta' : 'Control';
cy.realPress([modifier, 'A']); // select all
cy.realPress('Backspace'); // delete
});
cy.enterPromptValue('18');
});
it('GTurtle & Output', () => {
// type test program
cy.get('[test-id="megaEditor"]').eq(0).should('exist').type(programGTurtle);
// start program execution
cy.get('[test-id="megaStartBtn"]').click();
// await execution
cy.awaitExecutionTermination();
// check log
cy.get('[class="log-container"]')
.invoke('text')
.then((text) => {
// Create a regular expression pattern to match the expected values in order
const pattern = programGTurtleOutput.join('.*');
// Assert that the text contains the expected values in the right order using regex
expect(text).to.match(new RegExp(pattern));
});
// check canvas by state
cy.verifyCanvasOnCanvasStateBasis(programGTurtleState);
});
it('Log', () => {
// type test program
cy.get('[test-id="megaEditor"]').eq(0).should('exist').type(programLog);
// start program execution
cy.get('[test-id="megaStartBtn"]').click();
// await execution
cy.awaitExecutionTermination();
// check log
cy.get('[class="log-container"]')
.invoke('text')
.then((text) => {
// Create a regular expression pattern to match the expected values in order
const pattern = programLogOutput.join('.*');
// Assert that the text contains the expected values in the right order using regex
expect(text).to.match(new RegExp(pattern));
});
});
it('Prompt & Log', () => {
// type test program
cy.get('[test-id="megaEditor"]').eq(0).should('exist').type(programPrompt);
// start program execution
cy.get('[test-id="megaStartBtn"]').click();
//await dialog to appear to enter prompt value
cy.get('mat-dialog-content input', {timeout: 5000}).type('18');
cy.get('[test-id="confirmBtn"]').click();
cy.wait(2000);
cy.get('mat-dialog-content input', {timeout: 5000}).type('18');
cy.get('[test-id="confirmBtn"]').click();
// await execution
cy.awaitExecutionTermination();
// check log
cy.get('[class="log-container"]')
.invoke('text')
.then((text) => {
// Create a regular expression pattern to match the expected values in order
const pattern = programPromptOutput.join('.*');
// Assert that the text contains the expected values in the right order using regex
expect(text).to.match(new RegExp(pattern));
});
});
it('Numpy', () => {
// type test program
cy.get('[test-id="megaEditor"]').eq(0).should('exist').type(programNumpy);
// start program execution
cy.get('[test-id="megaStartBtn"]').click();
// await execution
cy.awaitExecutionTermination();
// check log
cy.get('[class="log-container"]')
.invoke('text')
.then((text) => {
// Create a regular expression pattern to match the expected values in order
const pattern = programNumpyOutput.join('.*');
// Assert that the text contains the expected values in the right order using regex
expect(text).to.match(new RegExp(pattern));
});
});
it('Speed Slider', () => {
//speed up program execution
cy.setMaxSpeedViaSlider();
// type test program
cy.get('[test-id="megaEditor"]')
.eq(0)
.should('exist')
.type(programSpeedSlider);
// start program execution
cy.get('[test-id="megaStartBtn"]').click();
// await execution
cy.awaitExecutionTermination();
// check canvas by amount of draw commands
cy.window().then((w) => {
const canvasState = JSON.stringify(w['getCanvasState']());
const commandsCount = canvasState.split('position').length - 1;
expect(commandsCount).to.equal(361);
});
});
it('Integrated Test', () => {
//speed up program execution
cy.setMaxSpeedViaSlider();
// type test program
cy.get('[test-id="megaEditor"]')
.eq(0)
.should('exist')
.type(programIntegrated);
// start program execution
cy.get('[test-id="megaStartBtn"]').click();
//await dialog to appear to enter prompt value
cy.get('mat-dialog-content input', {timeout: 5000}).type('18');
cy.get('[test-id="confirmBtn"]').click();
// await execution
cy.awaitExecutionTermination();
// check log
cy.get('[class="log-container"]')
.invoke('text')
.then((text) => {
// Create a regular expression pattern to match the expected values in order
const pattern = programIntegratedOutput.join('.*');
// Assert that the text contains the expected values in the right order using regex
expect(text).to.match(new RegExp(pattern));
});
});
});
Editor is loading...
Leave a Comment