-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from friedalexuni/main
Added B02 homework
- Loading branch information
Showing
5 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters