mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
Move cypress & netscript tests to ./test subfolder
This commit is contained in:
72
test/cypress/integration/naviguation.spec.ts
Normal file
72
test/cypress/integration/naviguation.spec.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
export {};
|
||||
|
||||
describe("netscript", () => {
|
||||
it("Do naviguation", () => {
|
||||
cy.findByRole("button", { name: "SKIP TUTORIAL" }).click();
|
||||
|
||||
cy.findByText("Dev").click();
|
||||
cy.findByText(/Source-Files/i).click();
|
||||
cy.findByLabelText(/all-sf-3/i).click();
|
||||
cy.findByText(/Experience/i).click();
|
||||
cy.findByText(/Tons of exp/i).click();
|
||||
cy.findByText(/General/i).click();
|
||||
cy.findByText(/Hack w0/i).click();
|
||||
cy.findByText(/SEMPOOL INVALID/i);
|
||||
cy.findByText(/Many decades/i, { timeout: 15000 });
|
||||
cy.findByLabelText("enter-bitnode-1").click();
|
||||
cy.findByText(/Enter BN1.2/i).click();
|
||||
|
||||
cy.get("body").type("{esc}");
|
||||
|
||||
cy.findByText("Dev").click();
|
||||
cy.findByText(/Experience/i).click();
|
||||
cy.findByText(/Tons of exp/i).click();
|
||||
|
||||
cy.findByText("Script Editor").click();
|
||||
cy.findByText(/No Open Files/i);
|
||||
|
||||
cy.findByText("Active Scripts").click();
|
||||
cy.findByText(/Total production since last Augment/i);
|
||||
|
||||
cy.findByText("Create Program").click();
|
||||
cy.findByText(/This page displays/i);
|
||||
|
||||
cy.findByText("Stats").click();
|
||||
cy.findByText(/Current City:/i);
|
||||
|
||||
cy.findByText("Factions").click();
|
||||
cy.findByText(/Lists all/i);
|
||||
|
||||
cy.findByText("Augmentations").click();
|
||||
cy.findByText(/Purchased Augmentations/i);
|
||||
|
||||
cy.findByText("Hacknet").click();
|
||||
cy.findByText(/The Hacknet is a global/i);
|
||||
|
||||
cy.findByText("Sleeves").click();
|
||||
cy.findByText(/Duplicate Sleeves are MK/i);
|
||||
|
||||
cy.findByText("City").click();
|
||||
cy.findByText(/Sector-12/i);
|
||||
cy.findByLabelText("The Slums").click();
|
||||
cy.findByText("City").click();
|
||||
cy.findByLabelText("Powerhouse Gym").click();
|
||||
cy.findByText("City").click();
|
||||
cy.findByLabelText("MegaCorp").click();
|
||||
|
||||
cy.findByText("Travel").click();
|
||||
cy.findByText(/Travel Agency/i);
|
||||
|
||||
cy.findByText("Stock Market").click();
|
||||
cy.findByText(/ECorp/i);
|
||||
|
||||
cy.findByText("Milestones").click();
|
||||
cy.findByText(/don't reward you for/i);
|
||||
|
||||
cy.findByText("Tutorial").click();
|
||||
cy.findByText(/Tutorial \/ Documentation/i);
|
||||
|
||||
cy.findByText("Options").click();
|
||||
cy.findByText(/\.script exec time/i);
|
||||
});
|
||||
});
|
||||
51
test/cypress/integration/netscript.spec.ts
Normal file
51
test/cypress/integration/netscript.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
export {};
|
||||
|
||||
describe("netscript", () => {
|
||||
it("creates and runs a NetScript 2.0 script", () => {
|
||||
cy.findByRole("button", { name: "SKIP TUTORIAL" }).click();
|
||||
|
||||
cy.findByRole("textbox").type("connect n00dles{enter}");
|
||||
cy.findByText(/connected to n00dles/i);
|
||||
|
||||
cy.findByRole("textbox").type("run NUKE.exe{enter}");
|
||||
cy.findByText(/gained root access/i);
|
||||
|
||||
cy.findByRole("textbox").type("home{enter}");
|
||||
cy.findByText(/connected to home/i);
|
||||
|
||||
cy.findByRole("textbox").type("nano script.js{enter}");
|
||||
|
||||
// monaco can take a bit
|
||||
cy.findByRole("code", { timeout: 15_000 }).type("{ctrl}a{del}").type(`export const main = async (ns) => {{}
|
||||
while(true) {{}
|
||||
await ns.hack("n00dles");`);
|
||||
|
||||
cy.findByText("RAM: 1.70GB");
|
||||
cy.findByRole("button", { name: /Save \(Ctrl\/Cmd \+ s\)/i }).click();
|
||||
cy.findByRole("button", { name: /Close \(Ctrl\/Cmd \+ b\)/i }).click();
|
||||
|
||||
cy.findByRole("textbox").type("run script.js{enter}");
|
||||
cy.findByText(/Running script with 1 thread/);
|
||||
|
||||
cy.findByRole("textbox").type("ps{enter}");
|
||||
cy.findByText(/\(PID - 1\) script.js/);
|
||||
});
|
||||
|
||||
it("errors and shows a dialog box when static RAM !== dynamic RAM", () => {
|
||||
cy.findByRole("button", { name: "SKIP TUTORIAL" }).click();
|
||||
|
||||
cy.findByRole("textbox").type("nano script.js{enter}");
|
||||
|
||||
// monaco can take a bit
|
||||
cy.findByRole("code", { timeout: 15_000 }).type("{ctrl}a{del}").type(`export const main = async (ns) => {{}
|
||||
const command = "hack";
|
||||
ns[command]("n00dles");`);
|
||||
|
||||
cy.findByText("RAM: 1.60GB");
|
||||
cy.findByRole("button", { name: /Save \(Ctrl\/Cmd \+ s\)/i }).click();
|
||||
cy.findByRole("button", { name: /Close \(Ctrl\/Cmd \+ b\)/i }).click();
|
||||
|
||||
cy.findByRole("textbox").type("run script.js{enter}");
|
||||
cy.findByText(/Dynamic RAM usage calculated to be greater than initial RAM usage on fn: hack./i);
|
||||
});
|
||||
});
|
||||
95
test/cypress/integration/tutorial.spec.ts
Normal file
95
test/cypress/integration/tutorial.spec.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
export {};
|
||||
|
||||
describe("tutorial", () => {
|
||||
it("completes the tutorial", () => {
|
||||
cy.findByText(/dark, dystopian future/);
|
||||
cy.findByRole("button", { name: "next" }).click();
|
||||
|
||||
cy.findByText(/heading to the Stats page/);
|
||||
cy.findByRole("button", { name: "Stats" }).click();
|
||||
|
||||
cy.findByText(/lot of important information/);
|
||||
cy.findByRole("button", { name: "next" }).click();
|
||||
|
||||
cy.findByText(/head to your computer's terminal/);
|
||||
cy.findByRole("button", { name: "Terminal" }).click();
|
||||
|
||||
cy.findByText(/is used to interface/);
|
||||
cy.findByRole("button", { name: "next" }).click();
|
||||
|
||||
cy.findByText(/Let's try it out/i);
|
||||
cy.findByRole("textbox").type("help{enter}");
|
||||
|
||||
cy.findByText(/displays a list of all available/i);
|
||||
cy.findByRole("textbox").type("ls{enter}");
|
||||
|
||||
cy.findByText(/is a basic command that shows files/i);
|
||||
cy.findByRole("textbox").type("scan{enter}");
|
||||
|
||||
cy.findByText(/that's great and all/i);
|
||||
cy.findByRole("textbox").type("scan-analyze{enter}");
|
||||
|
||||
cy.findByText(/shows more detailed information/i);
|
||||
cy.findByRole("textbox").type("scan-analyze 2{enter}");
|
||||
|
||||
cy.findByText(/now you can see information/i);
|
||||
cy.findByRole("textbox").type("connect n00dles{enter}");
|
||||
|
||||
cy.findByText(/currency has become digital/i);
|
||||
cy.findByRole("textbox").type("analyze{enter}");
|
||||
|
||||
cy.findByText(/For this server, the required hacking skill/i);
|
||||
cy.findByText(/Required number of open ports for NUKE/i);
|
||||
cy.findByRole("textbox").type("run NUKE.exe{enter}");
|
||||
|
||||
cy.findByText(/gained root access to n00dles/i);
|
||||
cy.findByRole("textbox").type("hack{enter}");
|
||||
|
||||
cy.findByText(/now attempting to hack the server/i);
|
||||
cy.findByRole("button", { name: "next" }).click();
|
||||
|
||||
cy.findByRole("textbox", { timeout: 15_000 }).should("not.be.disabled").type("home{enter}");
|
||||
|
||||
cy.findByRole("textbox").type("nano n00dles.script{enter}");
|
||||
|
||||
// monaco can take a bit
|
||||
cy.findByRole("code", { timeout: 15_000 }).type("{selectall}{del}").type("while(true) {{}{enter}hack('n00dles');");
|
||||
|
||||
cy.findByRole("button", { name: /Save \(Ctrl\/Cmd \+ s\)/i }).click();
|
||||
|
||||
cy.findByText(/now we'll run the script/i);
|
||||
cy.findByRole("textbox").type("free{enter}");
|
||||
|
||||
cy.findByText(/We have 8GB of free RAM on this machine/i);
|
||||
cy.findByRole("textbox").type("run n00dles.script{enter}");
|
||||
|
||||
cy.findByText(/Your script is now running/i);
|
||||
cy.findByRole("button", { name: "Active Scripts" }).click();
|
||||
|
||||
cy.findByText(/This page displays information about all of your scripts/i);
|
||||
cy.findByRole("button", { name: "Terminal" }).click();
|
||||
|
||||
cy.findByText(/each active script contains logs/i);
|
||||
cy.findByRole("textbox").type("tail n00dles.script{enter}");
|
||||
|
||||
cy.findByText(/The log for this script won't show much/i);
|
||||
cy.findByRole("button", { name: "next" }).click();
|
||||
|
||||
cy.findByText(/Hacking is not the only way to earn money/i);
|
||||
cy.findByRole("button", { name: "Hacknet" }).click();
|
||||
|
||||
cy.findByText(/Here you can purchase new Hacknet Nodes/i);
|
||||
cy.findByRole("button", { name: /Purchase Hacknet Node/ }).click();
|
||||
|
||||
cy.findByText(/You just purchased a Hacknet Node!/i);
|
||||
cy.findByRole("button", { name: "City" }).click();
|
||||
|
||||
cy.findByText(/This page lists all of the different locations/i);
|
||||
cy.findByRole("button", { name: "Tutorial" }).click();
|
||||
|
||||
cy.findByText(/a lot of different documentation about the game/i);
|
||||
cy.findByRole("button", { name: "FINISH TUTORIAL" }).click();
|
||||
|
||||
cy.findByText(/Tutorial \/ Documentation/i);
|
||||
});
|
||||
});
|
||||
22
test/cypress/plugins/index.js
Normal file
22
test/cypress/plugins/index.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/// <reference types="cypress" />
|
||||
// ***********************************************************
|
||||
// This example plugins/index.js can be used to load plugins
|
||||
//
|
||||
// You can change the location of this file or turn off loading
|
||||
// the plugins file with the 'pluginsFile' configuration option.
|
||||
//
|
||||
// You can read more here:
|
||||
// https://on.cypress.io/plugins-guide
|
||||
// ***********************************************************
|
||||
|
||||
// This function is called when a project is opened or re-opened (e.g. due to
|
||||
// the project's config changing)
|
||||
|
||||
/**
|
||||
* @type {Cypress.PluginConfig}
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
module.exports = (/*on, config*/) => {
|
||||
// `on` is used to hook into various events Cypress emits
|
||||
// `config` is the resolved Cypress config
|
||||
};
|
||||
1
test/cypress/support/commands.ts
Normal file
1
test/cypress/support/commands.ts
Normal file
@@ -0,0 +1 @@
|
||||
import "@testing-library/cypress/add-commands";
|
||||
10
test/cypress/support/globalHooks.ts
Normal file
10
test/cypress/support/globalHooks.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export {};
|
||||
|
||||
beforeEach(() => {
|
||||
cy.visit("/", {
|
||||
onBeforeLoad(win: Cypress.AUTWindow) {
|
||||
win.indexedDB.deleteDatabase("bitburnerSave");
|
||||
}
|
||||
});
|
||||
cy.clearLocalStorage();
|
||||
});
|
||||
21
test/cypress/support/index.js
Normal file
21
test/cypress/support/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// ***********************************************************
|
||||
// This example support/index.js is processed and
|
||||
// loaded automatically before your test files.
|
||||
//
|
||||
// This is a great place to put global configuration and
|
||||
// behavior that modifies Cypress.
|
||||
//
|
||||
// You can change the location of this file or turn off
|
||||
// automatically serving support files with the
|
||||
// 'supportFile' configuration option.
|
||||
//
|
||||
// You can read more here:
|
||||
// https://on.cypress.io/configuration
|
||||
// ***********************************************************
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import "./globalHooks";
|
||||
import "./commands";
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
@@ -1,13 +1,13 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
|
||||
import { Player } from "../../src/Player";
|
||||
import { NetscriptFunctions } from "../../src/NetscriptFunctions";
|
||||
import { getRamCost, RamCostConstants } from "../../src/Netscript/RamCostGenerator";
|
||||
import { Environment } from "../../src/Netscript/Environment";
|
||||
import { RunningScript } from "../../src/Script/RunningScript";
|
||||
import { Script } from "../../src/Script/Script";
|
||||
import { SourceFileFlags } from "../../src/SourceFile/SourceFileFlags";
|
||||
import { Player } from "../../../src/Player";
|
||||
import { NetscriptFunctions } from "../../../src/NetscriptFunctions";
|
||||
import { getRamCost, RamCostConstants } from "../../../src/Netscript/RamCostGenerator";
|
||||
import { Environment } from "../../../src/Netscript/Environment";
|
||||
import { RunningScript } from "../../../src/Script/RunningScript";
|
||||
import { Script } from "../../../src/Script/Script";
|
||||
import { SourceFileFlags } from "../../../src/SourceFile/SourceFileFlags";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
@@ -1,9 +1,9 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect } from "@jest/globals";
|
||||
|
||||
import { Player } from "../../src/Player";
|
||||
import { getRamCost, RamCostConstants } from "../../src/Netscript/RamCostGenerator";
|
||||
import { calculateRamUsage } from "../../src/Script/RamCalculations";
|
||||
import { Player } from "../../../src/Player";
|
||||
import { getRamCost, RamCostConstants } from "../../../src/Netscript/RamCostGenerator";
|
||||
import { calculateRamUsage } from "../../../src/Script/RamCalculations";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
@@ -1,8 +1,8 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
|
||||
import { Script } from "../../src/Script/Script";
|
||||
import { Player } from "../../src/Player";
|
||||
import { Script } from "../../../src/Script/Script";
|
||||
import { Player } from "../../../src/Player";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
@@ -26,4 +26,4 @@ describe("Validate Save Script Works", function () {
|
||||
expect(script.code).toEqual(code)
|
||||
expect(script.server).toEqual(server)
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,25 +1,25 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
|
||||
import { CONSTANTS } from "../src/Constants";
|
||||
import { Player } from "../src/Player";
|
||||
import { IMap } from "../src/types";
|
||||
import { CONSTANTS } from "../../src/Constants";
|
||||
import { Player } from "../../src/Player";
|
||||
import { IMap } from "../../src/types";
|
||||
|
||||
import { Company } from "../src/Company/Company";
|
||||
import { Server } from "../src/Server/Server";
|
||||
import { Company } from "../../src/Company/Company";
|
||||
import { Server } from "../../src/Server/Server";
|
||||
|
||||
import { buyStock, sellStock, shortStock, sellShort } from "../src/StockMarket/BuyingAndSelling";
|
||||
import { IStockMarket } from "../src/StockMarket/IStockMarket";
|
||||
import { Order } from "../src/StockMarket/Order";
|
||||
import { buyStock, sellStock, shortStock, sellShort } from "../../src/StockMarket/BuyingAndSelling";
|
||||
import { IStockMarket } from "../../src/StockMarket/IStockMarket";
|
||||
import { Order } from "../../src/StockMarket/Order";
|
||||
import {
|
||||
forecastForecastChangeFromCompanyWork,
|
||||
forecastForecastChangeFromHack,
|
||||
influenceStockThroughCompanyWork,
|
||||
influenceStockThroughServerGrow,
|
||||
influenceStockThroughServerHack,
|
||||
} from "../src/StockMarket/PlayerInfluencing";
|
||||
import { processOrders, IProcessOrderRefs } from "../src/StockMarket/OrderProcessing";
|
||||
import { Stock, StockForecastInfluenceLimit } from "../src/StockMarket/Stock";
|
||||
} from "../../src/StockMarket/PlayerInfluencing";
|
||||
import { processOrders, IProcessOrderRefs } from "../../src/StockMarket/OrderProcessing";
|
||||
import { Stock, StockForecastInfluenceLimit } from "../../src/StockMarket/Stock";
|
||||
import {
|
||||
cancelOrder,
|
||||
deleteStockMarket,
|
||||
@@ -29,15 +29,15 @@ import {
|
||||
processStockPrices,
|
||||
StockMarket,
|
||||
SymbolToStockMap,
|
||||
} from "../src/StockMarket/StockMarket";
|
||||
} from "../../src/StockMarket/StockMarket";
|
||||
import {
|
||||
forecastChangePerPriceMovement,
|
||||
getBuyTransactionCost,
|
||||
getSellTransactionGain,
|
||||
processTransactionForecastMovement,
|
||||
} from "../src/StockMarket/StockMarketHelpers";
|
||||
import { OrderTypes } from "../src/StockMarket/data/OrderTypes";
|
||||
import { PositionTypes } from "../src/StockMarket/data/PositionTypes";
|
||||
} from "../../src/StockMarket/StockMarketHelpers";
|
||||
import { OrderTypes } from "../../src/StockMarket/data/OrderTypes";
|
||||
import { PositionTypes } from "../../src/StockMarket/data/PositionTypes";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', {
|
||||
virtual: true,
|
||||
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
import { convertTimeMsToTimeElapsedString } from "../src/utils/StringHelperFunctions";
|
||||
import { convertTimeMsToTimeElapsedString } from "../../src/utils/StringHelperFunctions";
|
||||
|
||||
describe("StringHelperFunctions Tests", function () {
|
||||
it("transforms strings", () => {
|
||||
@@ -1,6 +1,6 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
import * as dirHelpers from "../../src/Terminal/DirectoryHelpers";
|
||||
import * as dirHelpers from "../../../src/Terminal/DirectoryHelpers";
|
||||
|
||||
describe("Terminal Directory Tests", function () {
|
||||
describe("removeLeadingSlash()", function () {
|
||||
@@ -2,12 +2,12 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
|
||||
import { Player } from "../../src/Player";
|
||||
import { determineAllPossibilitiesForTabCompletion } from "../../src/Terminal/determineAllPossibilitiesForTabCompletion";
|
||||
import { Server } from "../../src/Server/Server";
|
||||
import { AddToAllServers, prestigeAllServers } from "../../src/Server/AllServers";
|
||||
import { LocationName } from "../../src/Locations/data/LocationNames";
|
||||
import { CodingContract } from "../../src/CodingContracts";
|
||||
import { Player } from "../../../src/Player";
|
||||
import { determineAllPossibilitiesForTabCompletion } from "../../../src/Terminal/determineAllPossibilitiesForTabCompletion";
|
||||
import { Server } from "../../../src/Server/Server";
|
||||
import { AddToAllServers, prestigeAllServers } from "../../../src/Server/AllServers";
|
||||
import { LocationName } from "../../../src/Locations/data/LocationNames";
|
||||
import { CodingContract } from "../../../src/CodingContracts";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
140
test/netscript/tb_basic.script
Normal file
140
test/netscript/tb_basic.script
Normal file
@@ -0,0 +1,140 @@
|
||||
function test(name, val) {
|
||||
if (val) {
|
||||
tprint("Test " + name + ": OK");
|
||||
} else {
|
||||
tprint("Test " + name + ": FAILED");
|
||||
//A failed test prints failure to results text file
|
||||
write("tb_results.txt", "FAIL");
|
||||
}
|
||||
}
|
||||
|
||||
test("run", (args.length === 1 && args[0] === "OK"));
|
||||
|
||||
//Arithmetic
|
||||
test("arith1", 0 * 10 === 0);
|
||||
test("arith2", 0 + 1 === 1);
|
||||
test("arith3", 10 / 5 === 2);
|
||||
test("arith4", 6-3 === 3);
|
||||
test("arith5", 14 % 10 === 4);
|
||||
test("arith6", 5 === 24 / 6 + 1);
|
||||
test("arith7", 6 === 2 * 3);
|
||||
|
||||
//Logical operators
|
||||
test("logic1", true && true);
|
||||
test("logic2", !(true && false));
|
||||
test("logic3", true || false);
|
||||
test("logic4", !(false || false));
|
||||
test("logic5", 1 < 3);
|
||||
test("logic6", !(3 < 1));
|
||||
test("logic7", 5 >= 5);
|
||||
test("logic8", !(5 <= 4));
|
||||
test("logic9", true == true);
|
||||
test("logic10", true === true);
|
||||
test("logic11", !(0 != 0));
|
||||
|
||||
//Assignment
|
||||
i = 5;
|
||||
test("asgn1", i == 5);
|
||||
i = 0;
|
||||
test("asgn2", i === 0);
|
||||
test("asgn3", 10 === (i = 10));
|
||||
test("asgn4", i === 10);
|
||||
|
||||
|
||||
//Basic array functionality
|
||||
testArr = [1, 2, 3, 4, 5, "str1", "str2", "str3"];
|
||||
test("arr1", testArr[0] == 1);
|
||||
test("arr2", testArr[1] === 2);
|
||||
test("arr3", testArr[5] === "str1");
|
||||
test("arr4", testArr[7] === "str3");
|
||||
|
||||
x = 1;
|
||||
y = 2;
|
||||
z = 3;
|
||||
testArr = [];
|
||||
testArr.push(x);
|
||||
testArr.push(y);
|
||||
testArr.push(z);
|
||||
test("arr5", testArr.length === 3);
|
||||
test("arr6", 1 === testArr[0]);
|
||||
test("arr7", 3 === testArr[2]);
|
||||
|
||||
x = 10;
|
||||
y = 10;
|
||||
z = 10;
|
||||
test("arr8", testArr.toString() === "1,2,3");
|
||||
|
||||
testArr.push(4);
|
||||
testArr.push("some str");
|
||||
test("arr9", "1,2,3,4,some str" === testArr.toString());
|
||||
testArr.pop();
|
||||
test("arr10", "1,2,3,4" === testArr.toString());
|
||||
testArr.shift();
|
||||
test("arr11", "2,3,4" === testArr.toString());
|
||||
testArr.unshift(1);
|
||||
test("arr12", "1,2,3,4" === testArr.toString());
|
||||
|
||||
testArr[0] = 10;
|
||||
foo = 1;
|
||||
testArr[foo] = 11;
|
||||
foo = 2;
|
||||
testArr[foo] = 12;
|
||||
foo = 3;
|
||||
testArr[foo] = 13;
|
||||
test("arr13", "10,11,12,13" === testArr.join());
|
||||
testArr.splice(testArr.length, 2, 14, 15);
|
||||
test("arr14", testArr.length === 6);
|
||||
test("arr15", testArr.join() == "10,11,12,13,14,15");
|
||||
|
||||
//Short circuiting Logical Operators
|
||||
results = [];
|
||||
res = false || results.push("OK")
|
||||
res = (0 < -5) || results.push("OK")
|
||||
res = true && results.push("OK")
|
||||
res = (1 > 0) && results.push("OK")
|
||||
res = 5 && results.push("OK")
|
||||
|
||||
test("shortcircuit1", results.length === 5);
|
||||
for (i = 0; i < results.length; ++i) {
|
||||
test("shortcircuit" + (2 + i), results[i] === "OK");
|
||||
}
|
||||
|
||||
res = true || tprint('1');
|
||||
res = (true && true) || tprint('2');
|
||||
res = 1 > 0 || tprint('3');
|
||||
res = false && tprint('4');
|
||||
res = 1 < 0 && tprint('5');
|
||||
test("shortcircuit7", results.length === 5);
|
||||
|
||||
//Conditional Statements
|
||||
results = [];
|
||||
i = 1;
|
||||
if (i == 0) {
|
||||
results.push("FAIL");
|
||||
} else if (i == 2) {
|
||||
results.push("FAIL");
|
||||
} else if (i == 1) {
|
||||
results.push("OK");
|
||||
} else {
|
||||
results.push("FAIL");
|
||||
}
|
||||
|
||||
i = 5;
|
||||
if (i == 0) {
|
||||
results.push("FAIL");
|
||||
} else if (i == 2) {
|
||||
results.push("FAIL");
|
||||
} else if (i == 1) {
|
||||
results.push("FAIL");
|
||||
} else {
|
||||
results.push("OK");
|
||||
}
|
||||
|
||||
test("conditional1", results.length === 2);
|
||||
test("conditional2", results[0] === "OK");
|
||||
test("conditional3", results[1] === "OK");
|
||||
|
||||
run("tb_multiarray.script", 1, "OK");
|
||||
exec("tb_ports.script", "home", 1, "OK");
|
||||
|
||||
write("tb_results.txt", ",tb_basic");
|
||||
4
test/netscript/tb_foo.script
Normal file
4
test/netscript/tb_foo.script
Normal file
@@ -0,0 +1,4 @@
|
||||
while(true) {
|
||||
print("hi");
|
||||
sleep(5000);
|
||||
}
|
||||
119
test/netscript/tb_functions.script
Normal file
119
test/netscript/tb_functions.script
Normal file
@@ -0,0 +1,119 @@
|
||||
import {test} from "tb_basic.script";
|
||||
|
||||
test("run", (args.length === 1 && args[0] === "OK"));
|
||||
|
||||
//scan
|
||||
res = scan();
|
||||
test("scan1", res.includes("iron-gym") && res.includes("foodnstuff") &&
|
||||
res.includes("sigma-cosmetics") && res.includes("joesguns") &&
|
||||
res.includes("hong-fang-tea") && res.includes("harakiri-sushi"));
|
||||
test("scan2", res.length === 6);
|
||||
res = scan("foodnstuff");
|
||||
test("scan3", res.includes("home"));
|
||||
|
||||
//hasRootAccess and nuke
|
||||
svr = "foodnstuff";
|
||||
test("hasRootAccess1", !hasRootAccess(svr));
|
||||
test("nuke", nuke(svr));
|
||||
test("hasRootAccess2", hasRootAccess(svr));
|
||||
|
||||
//sleep and Date.now();
|
||||
time = Date.now();
|
||||
sleep(10000);
|
||||
time2 = Date.now();
|
||||
test("sleep", time2 - time > 8000);
|
||||
|
||||
//hack, grow, weaken, and their effects
|
||||
FORTIFYAMOUNT = 0.002;
|
||||
WEAKENAMOUNT = 0.05;
|
||||
|
||||
playerStartingMoney = getServerMoneyAvailable("home");
|
||||
serverStartingMoney = getServerMoneyAvailable("foodnstuff");
|
||||
startingSecLvl = getServerSecurityLevel("foodnstuff");
|
||||
|
||||
res = hack(svr);
|
||||
|
||||
playerEndingMoney = getServerMoneyAvailable("home");
|
||||
serverEndingMoney = getServerMoneyAvailable("foodnstuff");
|
||||
endingSecLvl = getServerSecurityLevel("foodnstuff");
|
||||
|
||||
success = !(res == 0);
|
||||
|
||||
if (success) {
|
||||
tprint("Hack succeeded");
|
||||
test("hackplyrmoney", res === (playerEndingMoney - playerStartingMoney));
|
||||
test("hacksvrmoney", res === (serverStartingMoney - serverEndingMoney));
|
||||
//Dumb JS precision
|
||||
test("seclevel", (endingSecLvl - startingSecLvl) - FORTIFYAMOUNT < 1e2 * Number.EPSILON);
|
||||
} else {
|
||||
tprint("Hack failed");
|
||||
test("hackres", res === 0);
|
||||
test("hackplymoney", playerEndingMoney === playerStartingMoney);
|
||||
test("hacksvrmoney", serverEndingMoney === serverStartingMoney);
|
||||
test("seclevel", endingSecLvl === startingSecLvl);
|
||||
}
|
||||
|
||||
serverStartingMoney = getServerMoneyAvailable(svr);
|
||||
res = grow(svr);
|
||||
serverEndingMoney = getServerMoneyAvailable(svr);
|
||||
test("grow", serverEndingMoney > serverStartingMoney);
|
||||
test("growtest", res * serverStartingMoney - serverEndingMoney < Number.EPSILON);
|
||||
|
||||
startingSecLvl = getServerSecurityLevel(svr);
|
||||
res = weaken(svr);
|
||||
endingSecLvl = getServerSecurityLevel(svr);
|
||||
test("weaken", res === WEAKENAMOUNT);
|
||||
test("weakenres", startingSecLvl - endingSecLvl - res < 1e2 * Number.EPSILON);
|
||||
|
||||
//misc getter functions
|
||||
test("getHostname", getHostname() === "home");
|
||||
test("getHackingLevel", getHackingLevel() >= 1); //Can vary based on aug mults
|
||||
res = getHackingMultipliers();
|
||||
test("getHackingMultipliers", res.chance >= 1 && res.speed >= 1 &&
|
||||
res.money >= 1 && res.growth >= 1);
|
||||
svr = "joesguns";
|
||||
baseSecLvl = getServerBaseSecurityLevel(svr);
|
||||
minSecLvl = getServerMinSecurityLevel(svr);
|
||||
test("getServerBase/MinSecurityLevel1", minSecLvl < baseSecLvl);
|
||||
test("getServerBase/MinSecurityLevel1", minSecLvl === Math.max(1, Math.round(baseSecLvl / 3)));
|
||||
test("getServerRequiredHackingLevel", getServerRequiredHackingLevel(svr) === 10);
|
||||
test("getServerMaxMoney", getServerMaxMoney(svr) > getServerMoneyAvailable(svr)); //Can vary by BN
|
||||
test("getServerGrowth", getServerGrowth(svr) >= 1); //Can vary by BN
|
||||
test("getServerNumPortsRequired1", getServerNumPortsRequired(svr) === 0);
|
||||
test("getServerNumPortsRequired1", getServerNumPortsRequired("neo-net") === 1);
|
||||
test("getServerRam", getServerRam("home")[0] === 8 ||
|
||||
getServerRam("home")[0] === 16 ||
|
||||
getServerRam("home")[0] === 32);
|
||||
test("serverExists1", serverExists("home"));
|
||||
test("serverExists2", !serverExists("foofooofofofof"));
|
||||
test("fileExists1", fileExists("tb_start.script"));
|
||||
test("fileExists2", !fileExists("tosdifoodafgbiofdagbaod.txt"));
|
||||
|
||||
//run a misc script
|
||||
test("isRunning1", !isRunning("tb_foo.script", "home"));
|
||||
run("tb_foo.script", 1, 1, 2, 3);
|
||||
test("isRunning2", !isRunning("tb_foo.script", "home", "foo"));
|
||||
test("isRunning3", isRunning("tb_foo.script", "home", 1, 2, 3));
|
||||
|
||||
//kill
|
||||
kill("tb_foo.script", "home", "fee");
|
||||
sleep(10000);
|
||||
test("isRunning4", isRunning("tb_foo.script", "home", 1, 2, 3));
|
||||
kill("tb_foo.script", "home", 1, 2, 3);
|
||||
sleep(10000);
|
||||
test("isRunning4", !isRunning("tb_foo.script", "home", 1, 2, 3));
|
||||
|
||||
//scp
|
||||
svr = "foodnstuff";
|
||||
test("fileExists3", !fileExists("tb_remote.script", svr));
|
||||
test("fileExists4", !fileExists("tb_basic.script", svr));
|
||||
scp("tb_remote.script", "home", svr);
|
||||
scp("tb_basic.script", svr);
|
||||
test("fileExists5", fileExists("tb_remote.script", svr));
|
||||
test("fileExists6", fileExists("tb_basic.script", svr));
|
||||
|
||||
write("tb_results.txt", ",tb_functions"); //Done, pretty much
|
||||
|
||||
//exec and spawn
|
||||
exec("tb_remote.script", "foodnstuff", 1, "OK");
|
||||
spawn("tb_functions2.script", 1, "OK");
|
||||
90
test/netscript/tb_multiarray.script
Normal file
90
test/netscript/tb_multiarray.script
Normal file
@@ -0,0 +1,90 @@
|
||||
//Tests for multidimensional arrays
|
||||
import {test} from "tb_basic.script";
|
||||
|
||||
runSuccess = (args.length === 1 && args[0] === "OK");
|
||||
test("run", runSuccess);
|
||||
|
||||
arr = [];
|
||||
arr[0] = [];
|
||||
arr[1] = [];
|
||||
arr.push([]);
|
||||
|
||||
test("multiarr1", arr.toString() === ",,");
|
||||
test("multiarr2", arr.length === 3);
|
||||
arr[0].push(0);
|
||||
arr[0].push(0);
|
||||
arr[0].push(0);
|
||||
test("multiarr3", arr[0].length === 3);
|
||||
test("multiarr4", arr[0].toString() === "0,0,0");
|
||||
arr[1] = [0, 0, 0];
|
||||
test("multiarr5", arr.length === 3);
|
||||
test("multiarr6", arr[1].length === 3);
|
||||
test("multiarr7", arr[1].toString() === "0,0,0");
|
||||
arr.pop();
|
||||
arr.push([0,0,0]);
|
||||
test("multiarr8", arr.length === 3);
|
||||
test("multiarr9", arr[2].length === 3);
|
||||
test("multiarr10", "0,0,0,0,0,0,0,0,0" === arr.toString());
|
||||
for (r = 0; r < arr.length; ++r) {
|
||||
for (c = 0; c < arr[r].length; ++c) {
|
||||
arr[r][c] = r * 3 + c + 1;
|
||||
}
|
||||
}
|
||||
test("multiarr11", "1,2,3,4,5,6,7,8,9" === arr.toString());
|
||||
|
||||
arr = [[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]];
|
||||
test("multiarr12", 4 === arr.length);
|
||||
for (i = 0; i < arr.length; ++i) {
|
||||
test("multiarr" + (13 + i), arr[i].length === 4);
|
||||
}
|
||||
|
||||
for (r = 0; r < arr.length; ++r) {
|
||||
for (c = 0; c < arr[r].length; ++c) {
|
||||
arr[r][c] = r * 10 + c + 1;
|
||||
}
|
||||
}
|
||||
|
||||
test("multiarr17", arr.toString() === "1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34");
|
||||
|
||||
|
||||
//3D array
|
||||
arr = [[], [], [], []];
|
||||
arr[0].push([0, 0, 0]);
|
||||
arr[0].push([0, 0, 0]);
|
||||
arr[0].push([0, 0, 0]);
|
||||
|
||||
arr[1].push([0, 0, 0]);
|
||||
arr[1].push([0, 0, 0]);
|
||||
arr[1].push([0, 0, 0]);
|
||||
|
||||
arr[2].push([0, 0, 0]);
|
||||
arr[2].push([0, 0, 0]);
|
||||
arr[2].push([0, 0, 0]);
|
||||
|
||||
arr[3].push([0, 0, 0]);
|
||||
arr[3].push([0, 0, 0]);
|
||||
arr[3].push([0, 0, 0]);
|
||||
|
||||
i = 0;
|
||||
|
||||
for (r = 0; r < arr.length; ++r) {
|
||||
for (c = 0; c < arr[r].length; ++c) {
|
||||
for (d = 0; d < arr[r][c].length; ++d) {
|
||||
arr[r][c][d] = i;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("multiarr18", "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35" === arr.toString());
|
||||
ref = 0;
|
||||
for (r = 0; r < arr.length; ++r) {
|
||||
for (c = 0; c < arr[r].length; ++c) {
|
||||
for (d = 0; d < arr[r][c].length; ++d) {
|
||||
test("multiarr" + (19 + ref), arr[r][c][d] === ref);
|
||||
++ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write("tb_results.txt", ",tb_multiarray");
|
||||
73
test/netscript/tb_ports.script
Normal file
73
test/netscript/tb_ports.script
Normal file
@@ -0,0 +1,73 @@
|
||||
import {test} from "tb_basic.script";
|
||||
|
||||
test("run", (args.length === 1 && args[0] === "OK"));
|
||||
|
||||
|
||||
MAXPORTS = 20;
|
||||
MAXPORTSIZE = 100;
|
||||
|
||||
for (i = 1; i <= MAXPORTS; ++i) {
|
||||
clear(i);
|
||||
}
|
||||
|
||||
//write
|
||||
for (i = 1; i <= MAXPORTS; ++i) {
|
||||
for (j = 1; j <= 5; ++j) {
|
||||
write(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= MAXPORTS; ++i) {
|
||||
port = getPortHandle(i);
|
||||
test("write" + i, port.data.length === 5);
|
||||
}
|
||||
|
||||
//read
|
||||
for (i = 1; i <= MAXPORTS; ++i) {
|
||||
for (j = 1; j <= 2; ++j) {
|
||||
res = read(i);
|
||||
test("read-p" + i + "-" + j, res === j);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= MAXPORTS; ++i) {
|
||||
port = getPortHandle(i); //Check that read removes elements
|
||||
test("readpops" + i, port.data.length === 3);
|
||||
}
|
||||
|
||||
//peek
|
||||
for (i = 1; i <= MAXPORTS; ++i) {
|
||||
test("peek" + i, peek(i) === 3);
|
||||
port = getPortHandle(i);
|
||||
test("peeknopop" + i, port.data.length === 3);
|
||||
}
|
||||
|
||||
//clear and empty
|
||||
for (i = 1; i <= MAXPORTS; ++i) {
|
||||
clear(i);
|
||||
port = getPortHandle(i);
|
||||
test("clear" + i, port.data.length === 0);
|
||||
test("empty" + i, port.empty());
|
||||
}
|
||||
|
||||
//Write so that the port is full (only port 1 for this)
|
||||
for (i = 0; i < MAXPORTSIZE + 1; ++i) {
|
||||
write(1, i)
|
||||
}
|
||||
|
||||
//full
|
||||
port = getPortHandle(1);
|
||||
test("full", port.full());
|
||||
test("notempty", !port.empty());
|
||||
|
||||
//tryWrite
|
||||
firstElem = peek(1);
|
||||
test("trywritefails", !port.tryWrite("foo"));
|
||||
test("trywritenochange", peek(1) === firstElem);
|
||||
read(1);
|
||||
test("trywritesucceeds", port.tryWrite("foo"));
|
||||
test("trywritewrites", port.data.pop() === "foo");
|
||||
test("notfull", !port.full());
|
||||
|
||||
write("tb_results.txt", ",tb_ports");
|
||||
run("tb_functions.script", 1, "OK");
|
||||
17
test/netscript/tb_remote.script
Normal file
17
test/netscript/tb_remote.script
Normal file
@@ -0,0 +1,17 @@
|
||||
import {test} from "tb_basic.script";
|
||||
|
||||
test("run", args.length === 1 && args[0] === "OK");
|
||||
|
||||
svr = "foodnstuff";
|
||||
test("getHostname", getHostname() === svr);
|
||||
//ls
|
||||
res = ls(svr);
|
||||
test("ls1", res.includes("sector-12-crime.lit"));
|
||||
test("ls2", res.includes("tb_remote.script"));
|
||||
test("ls3", res.includes("tb_basic.script"));
|
||||
test("ls4", res.length === 3);
|
||||
res = ls(svr, ".lit");
|
||||
test("ls5", res.length === 1);
|
||||
test("ls6", res.includes("sector-12-crime.lit"));
|
||||
|
||||
write("tb_results.txt", "tb_remote");
|
||||
35
test/netscript/tb_start.script
Normal file
35
test/netscript/tb_start.script
Normal file
@@ -0,0 +1,35 @@
|
||||
tprint("Beginning testbench. A soft reset MUST be performed before running this.");
|
||||
tprint("This should be run on a Bitnode between 1 and 7, with $100k+, 16GB RAM+ " +
|
||||
"and access to Singularity functions otherwise some tests may fail");
|
||||
|
||||
run("tb_basic.script", 1, "OK");
|
||||
write("tb_results.txt", "tb_start", "w");
|
||||
|
||||
while(true) {
|
||||
sleep(10000);
|
||||
res = read("tb_results.txt");
|
||||
if (res.includes("FAIL")) {
|
||||
tprint("TESTBENCH FAILED");
|
||||
killall();
|
||||
}
|
||||
if (res.includes("tb_start") && res.includes("tb_basic") &&
|
||||
res.includes("tb_ports") && res.includes("tb_multiarray") &&
|
||||
res.includes("tb_functions")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Check remote
|
||||
scp("tb_results.txt", "foodnstuff", "home");
|
||||
res = read("tb_results.txt");
|
||||
if (res.includes("FAIL")) {
|
||||
tprint("TESTBENCH FAILED");
|
||||
killall();
|
||||
}
|
||||
if (res.includes("tb_remote")) {
|
||||
tprint("TESTBENCH SUCCESS");
|
||||
} else {
|
||||
tprint("TESTBENCH FAILED");
|
||||
killall();
|
||||
}
|
||||
Reference in New Issue
Block a user