Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up: Array to buffer as Buffer.fromArray, (not Array.buffer). #389

Merged
merged 9 commits into from
Jun 17, 2022
Merged
7 changes: 0 additions & 7 deletions src/Array.mo
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,4 @@ module {
});
};

public func buffer<A>(xs : [A]) : Buffer.Buffer<A> {
let buff = Buffer.Buffer<A>(xs.size());
for (x in xs.vals()) {
buff.add(x)
};
buff
};
}
7 changes: 7 additions & 0 deletions src/Buffer.mo
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,11 @@ module {
};
};

public func fromArray<A>(xs : [A]) : Buffer<A> {
let buff = Buffer<A>(xs.size());
for (x in xs.vals()) {
buff.add(x)
};
buff
};
}
5 changes: 0 additions & 5 deletions test/arrayTest.mo
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ let suite = Suite.suite("Array", [
"reverse",
Array.reverse<Nat>([0, 1, 2, 3]),
M.equals(T.array<Nat>(T.natTestable, [3, 2, 1, 0]))
),
Suite.test(
"buffer",
Array.buffer<Nat>([0, 1, 2, 3]).toArray(),
M.equals(T.array<Nat>(T.natTestable, [0, 1, 2, 3]))
)
]);

Expand Down
10 changes: 10 additions & 0 deletions test/bufTest.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import B "mo:base/Buffer";
import I "mo:base/Iter";
import O "mo:base/Option";

import Suite "mo:matchers/Suite";
import T "mo:matchers/Testable";
import M "mo:matchers/Matchers";

// test repeated growing
let a = B.Buffer<Nat>(3);
for (i in I.range(0, 123)) {
Expand Down Expand Up @@ -92,3 +96,9 @@ do {
assert (c.toArray().size() == 2);
assert (c.toVarArray().size() == 2);
};

Suite.test(
"fromArray",
B.fromArray<Nat>([0, 1, 2, 3]).toArray(),
M.equals(T.array<Nat>(T.natTestable, [0, 1, 2, 3]))
);