-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d7b029
commit 008cd79
Showing
3 changed files
with
138 additions
and
1 deletion.
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
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,80 @@ | ||
encapsulated package StringVector | ||
import BaseVector; | ||
extends BaseVector(redeclare type T = String, defaultValue = ""); | ||
annotation(__OpenModelica_Interface="util"); | ||
end StringVector; | ||
|
||
function print_vector | ||
input StringVector.Vector inVector; | ||
protected | ||
Integer sz = StringVector.size(inVector); | ||
Integer capacity = StringVector.capacity(inVector); | ||
algorithm | ||
print("["); | ||
for i in 1:sz loop | ||
print(StringVector.get(inVector, i)); | ||
if i <> capacity then print(", "); end if; | ||
end for; | ||
|
||
for i in (sz+1):capacity loop | ||
print("_"); | ||
if i <> capacity then print(", "); end if; | ||
end for; | ||
print("]\n"); | ||
end print_vector; | ||
|
||
partial function test | ||
protected | ||
StringVector.Vector vec; | ||
end test; | ||
|
||
// Tests basic operations | ||
function test1 extends test; | ||
algorithm | ||
vec := StringVector.new(4); | ||
print("isEmpty = " + boolString(StringVector.isEmpty(vec)) + "\n"); | ||
StringVector.add(vec, "test1"); print_vector(vec); | ||
print("isEmpty = " + boolString(StringVector.isEmpty(vec)) + "\n"); | ||
StringVector.add(vec, "test2"); print_vector(vec); | ||
StringVector.add(vec, "test3"); print_vector(vec); | ||
StringVector.add(vec, "test4"); print_vector(vec); | ||
StringVector.add(vec, "test5"); print_vector(vec); | ||
StringVector.add(vec, "test6"); print_vector(vec); | ||
StringVector.add(vec, "test7"); print_vector(vec); | ||
StringVector.add(vec, "test8"); print_vector(vec); | ||
StringVector.add(vec, "test9"); print_vector(vec); | ||
StringVector.add(vec, "test10"); print_vector(vec); | ||
StringVector.set(vec, 5, "test5b"); print_vector(vec); | ||
StringVector.set(vec, 1, "test1b"); print_vector(vec); | ||
StringVector.set(vec, 10, "test10b"); print_vector(vec); | ||
end test1; | ||
|
||
// Tests resizing operations. | ||
function test2 extends test; | ||
algorithm | ||
vec := StringVector.new(); print_vector(vec); | ||
StringVector.reserve(vec, 5); print_vector(vec); | ||
StringVector.resize(vec, 6, "test"); print_vector(vec); | ||
StringVector.resize(vec, 3, "test2"); print_vector(vec); | ||
StringVector.trim(vec); print_vector(vec); | ||
StringVector.resize(vec, 10, "test2"); print_vector(vec); | ||
StringVector.pop(vec); print_vector(vec); | ||
StringVector.trim(vec); print_vector(vec); | ||
StringVector.pop(vec); print_vector(vec); | ||
end test2; | ||
|
||
// Tests fill operations. | ||
function test3 extends test; | ||
algorithm | ||
vec := StringVector.newFill(8, "123"); print_vector(vec); | ||
StringVector.fill(vec, "abc"); print_vector(vec); | ||
StringVector.fill(vec, "xyz", 3); print_vector(vec); | ||
StringVector.fill(vec, "123", 5, 7); print_vector(vec); | ||
end test3; | ||
|
||
// Checks that attempting to write to an element out of bounds fails. | ||
function test4 extends test; | ||
algorithm | ||
vec := StringVector.new(4); | ||
StringVector.set(vec, 1, "test"); | ||
end test4; |
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,56 @@ | ||
// name: VectorTest | ||
// cflags: +g=MetaModelica +d=rml | ||
// status: correct | ||
// teardown_command: rm -f VectorTest_* | ||
|
||
loadFile("../../../OMCompiler/Compiler/Util/BaseVector.mo"); | ||
getErrorString(); | ||
loadFile("VectorTest.mo"); | ||
getErrorString(); | ||
test1(); getErrorString(); | ||
test2(); getErrorString(); | ||
test3(); getErrorString(); | ||
test4(); getErrorString(); | ||
|
||
// Result: | ||
// true | ||
// "" | ||
// true | ||
// "" | ||
// isEmpty = true | ||
// [test1, _, _, _] | ||
// isEmpty = false | ||
// [test1, test2, _, _] | ||
// [test1, test2, test3, _] | ||
// [test1, test2, test3, test4] | ||
// [test1, test2, test3, test4, test5, _, _, _] | ||
// [test1, test2, test3, test4, test5, test6, _, _] | ||
// [test1, test2, test3, test4, test5, test6, test7, _] | ||
// [test1, test2, test3, test4, test5, test6, test7, test8] | ||
// [test1, test2, test3, test4, test5, test6, test7, test8, test9, _, _, _, _, _, _, _] | ||
// [test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, _, _, _, _, _, _] | ||
// [test1, test2, test3, test4, test5b, test6, test7, test8, test9, test10, _, _, _, _, _, _] | ||
// [test1b, test2, test3, test4, test5b, test6, test7, test8, test9, test10, _, _, _, _, _, _] | ||
// [test1b, test2, test3, test4, test5b, test6, test7, test8, test9, test10b, _, _, _, _, _, _] | ||
// | ||
// "" | ||
// [_] | ||
// [_, _, _, _, _] | ||
// [test, test, test, test, test, test] | ||
// [test, test, test, _, _, _] | ||
// [test, test, test] | ||
// [test, test, test, test2, test2, test2, test2, test2, test2, test2] | ||
// [test, test, test, test2, test2, test2, test2, test2, test2, _] | ||
// [test, test, test, test2, test2, test2, test2, test2, test2, _] | ||
// [test, test, test, test2, test2, test2, test2, test2, _, _] | ||
// | ||
// "" | ||
// [123, 123, 123, 123, 123, 123, 123, 123] | ||
// [abc, abc, abc, abc, abc, abc, abc, abc] | ||
// [abc, abc, xyz, xyz, xyz, xyz, xyz, xyz] | ||
// [abc, abc, xyz, xyz, 123, 123, 123, xyz] | ||
// | ||
// "" | ||
// fail() | ||
// "" | ||
// endResult |