Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkriehle committed Nov 10, 2024
2 parents 090670d + 247c2d8 commit 0a0dee1
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 18 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ jobs:

- name: Run tests for exercise B01
run: npm run test:b01
if: ${{ !cancelled() }}
if: ${{ !cancelled() && github.event.head_commit.timestamp >= '2024-10-21T12:00:00Z' }}

- name: Run tests for exercise B02
run: npm run test:b02
if: ${{ !cancelled() }}
if: ${{ !cancelled() && github.event.head_commit.timestamp >= '2024-10-28T12:00:00Z' }}

- name: Run tests for exercise B03
run: npm run test:b03
if: ${{ !cancelled() }}
if: ${{ !cancelled() && github.event.head_commit.timestamp >= '2024-11-11T12:00:00Z' }}

- name: Run tests for exercise B04
run: npm run test:b04
if: ${{ !cancelled() }}
if: ${{ !cancelled() && github.event.head_commit.timestamp >= '2024-11-18T12:00:00Z' }}

- name: Run tests for exercise B05
run: npm run test:b05
if: ${{ !cancelled() }}
if: ${{ !cancelled() && github.event.head_commit.timestamp >= '2024-11-25T12:00:00Z' }}

- name: Run tests for exercise B06
run: npm run test:b06
if: ${{ !cancelled() }}
if: ${{ !cancelled() && github.event.head_commit.timestamp >= '2024-12-02T12:00:00Z' }}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"scripts": {
"build": "tsc",
"test": "vitest",
"test:b01": "vitest --dir test/adap-b01*",
"test:b02": "vitest --dir test/adap-b02*",
"test:b03": "vitest --dir test/adap-b03*",
"test:b04": "vitest --dir test/adap-b04*",
"test:b05": "vitest --dir test/adap-b05*",
"test:b06": "vitest --dir test/adap-b06*"
"test:b01": "vitest --dir test/adap-b01 --passWithNoTests",
"test:b02": "vitest --dir test/adap-b02 --passWithNoTests",
"test:b03": "vitest --dir test/adap-b03 --passWithNoTests",
"test:b04": "vitest --dir test/adap-b04 --passWithNoTests",
"test:b05": "vitest --dir test/adap-b05 --passWithNoTests",
"test:b06": "vitest --dir test/adap-b06 --passWithNoTests"
},
"keywords": [],
"author": "Dirk Riehle",
Expand Down
35 changes: 33 additions & 2 deletions src/adap-b02/names/Name.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@
export const DEFAULT_DELIMITER: string = '.';
export const ESCAPE_CHARACTER = '\\';

/**
* A name is a sequence of string components separated by a delimiter character.
* Special characters within the string may need masking, if they are to appear verbatim.
* There are only two special characters, the delimiter character and the escape character.
* The escape character can't be set, the delimiter character can.
*
* Homogenous name examples
*
* "oss.cs.fau.de" is a name with four name components and the delimiter character '.'.
* "///" is a name with four empty components and the delimiter character '/'.
* "Oh\.\.\." is a name with one component, if the delimiter character is '.'.
*/
export interface Name {

/** Returns human-readable representation of Name instance */
asNameString(delimiter?: string): string;
/**
* Returns a human-readable representation of the Name instance using user-set control characters
* Control characters are not escaped (creating a human-readable string)
* Users can vary the delimiter character to be used
*/
asString(delimiter?: string): string;

/**
* Returns a machine-readable representation of Name instance using default control characters
* Machine-readable means that from a data string, a Name can be parsed back in
* The control characters in the data string are the default characters
*/
asDataString(): string;

isEmpty(): boolean;

getDelimiterCharacter(): string;

/** Returns number of components in Name instance */
getNoComponents(): number;

getComponent(i: number): string;

/** Assumes that new Name component c is properly masked */
setComponent(i: number, c: string): void;

/** Assumes that new Name component c is properly masked */
insert(i: number, c: string): void;

/** Assumes that new Name component c is properly masked */
append(c: string): void;

remove(i: number): void;

}
10 changes: 9 additions & 1 deletion src/adap-b02/names/StringArrayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ export class StringArrayName implements Name {
throw new Error("needs implementation");
}

public asNameString(delimiter: string = this.delimiter): string {
public asString(delimiter: string = this.delimiter): string {
throw new Error("needs implementation");
}

public asDataString(): string {
throw new Error("needs implementation");
}

public isEmpty(): boolean {
throw new Error("needs implementation");
}

public getDelimiterCharacter(): string {
throw new Error("needs implementation");
}

public getNoComponents(): number {
throw new Error("needs implementation");
}
Expand Down
12 changes: 10 additions & 2 deletions src/adap-b02/names/StringName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@ export class StringName implements Name {
protected delimiter: string = DEFAULT_DELIMITER;

protected name: string = "";
protected length: number = 0; // Number of components in Name instance
protected length: number = 0;

constructor(other: string, delimiter?: string) {
throw new Error("needs implementation");
}

public asNameString(delimiter: string = this.delimiter): string {
public asString(delimiter: string = this.delimiter): string {
throw new Error("needs implementation");
}

public asDataString(): string {
throw new Error("needs implementation");
}

public isEmpty(): boolean {
throw new Error("needs implementation");
}

public getDelimiterCharacter(): string {
throw new Error("needs implementation");
}

public getNoComponents(): number {
throw new Error("needs implementation");
}
Expand Down
59 changes: 59 additions & 0 deletions test/adap-b02/names/Name.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, it, expect } from "vitest";

import { Name } from "../../../src/adap-b02/names/Name";
import { StringName } from "../../../src/adap-b02/names/StringName";
import { StringArrayName } from "../../../src/adap-b02/names/StringArrayName";

describe("Basic StringName function tests", () => {
it("test insert", () => {
let n: Name = new StringName("oss.fau.de");
n.insert(1, "cs");
expect(n.asString()).toBe("oss.cs.fau.de");
});
it("test append", () => {
let n: Name = new StringName("oss.cs.fau");
n.append("de");
expect(n.asString()).toBe("oss.cs.fau.de");
});
it("test remove", () => {
let n: Name = new StringName("oss.cs.fau.de");
n.remove(0);
expect(n.asString()).toBe("cs.fau.de");
});
});

describe("Basic StringArrayName function tests", () => {
it("test insert", () => {
let n: Name = new StringArrayName(["oss", "fau", "de"]);
n.insert(1, "cs");
expect(n.asString()).toBe("oss.cs.fau.de");
});
it("test append", () => {
let n: Name = new StringArrayName(["oss", "cs", "fau"]);
n.append("de");
expect(n.asString()).toBe("oss.cs.fau.de");
});
it("test remove", () => {
let n: Name = new StringArrayName(["oss", "cs", "fau", "de"]);
n.remove(0);
expect(n.asString()).toBe("cs.fau.de");
});
});

describe("Delimiter function tests", () => {
it("test insert", () => {
let n: Name = new StringName("oss#fau#de", '#');
n.insert(1, "cs");
expect(n.asString()).toBe("oss#cs#fau#de");
});
});

describe("Escape character extravaganza", () => {
it("test escape and delimiter boundary conditions", () => {
let n: Name = new StringName("oss.cs.fau.de", '#');
expect(n.getNoComponents()).toBe(1);
expect(n.asString()).toBe("oss.cs.fau.de");
n.append("people");
expect(n.asString()).toBe("oss.cs.fau.de#people");
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2023", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
Expand Down

0 comments on commit 0a0dee1

Please sign in to comment.