Skip to content

Commit

Permalink
in-memory tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Apr 20, 2023
1 parent 2ec87c0 commit ab09a27
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type Operation_Type_Helpers
> Example

type_helpers.check_argument_type other Value_Type.expect_text <| operation
check_argument_type self value type_check action =
check_argument_type self value type_check ~action =
typ = self.find_argument_type value
if typ.is_nothing then action else
related_column = if self.is_column value then value.name else Nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public BoolStorage runZip(DoubleStorage storage, Storage<?> arg, MapOperationPro
BitSet newMissing = new BitSet();
for (int i = 0; i < storage.size(); i++) {
if (!storage.isNa(i) && i < v.size() && !v.isNa(i)) {
if (doDouble(storage.getItem(i), v.getItem(i))) {
if (doDouble(storage.getItem(i), v.getItemDouble(i))) {
newVals.set(i);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.enso.table.data.column.operation.map.text;

import org.enso.table.data.column.builder.object.StringBuilder;
import org.enso.table.data.column.operation.map.MapOperation;
import org.enso.table.data.column.operation.map.MapOperationProblemBuilder;
import org.enso.table.data.column.storage.SpecializedStorage;
import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.column.storage.StringStorage;
import org.enso.table.error.UnexpectedTypeException;

public abstract class StringStringOp extends MapOperation<String, SpecializedStorage<String>> {
public StringStringOp(String name) {
super(name);
}

protected abstract String doString(String a, String b);

@Override
public Storage<?> runMap(SpecializedStorage<String> storage, Object arg, MapOperationProblemBuilder problemBuilder) {
int size = storage.size();
if (arg == null) {
StringBuilder builder = new StringBuilder(size);
builder.appendNulls(size);
return builder.seal();
} else if (arg instanceof String argString) {
String[] newVals = new String[size];
for (int i = 0; i < size; i++) {
if (storage.isNa(i)) {
newVals[i] = null;
} else {
newVals[i] = doString(storage.getItem(i), argString);
}
}
return new StringStorage(newVals, size);
} else {
throw new UnexpectedTypeException("a Text");
}
}

@Override
public Storage<?> runZip(SpecializedStorage<String> storage, Storage<?> arg,
MapOperationProblemBuilder problemBuilder) {
if (arg instanceof StringStorage v) {
int size = storage.size();
String[] newVals = new String[size];
for (int i = 0; i < size; i++) {
if (storage.isNa(i) || v.isNa(i)) {
newVals[i] = null;
} else {
newVals[i] = doString(storage.getItem(i), v.getItem(i));
}
}
return new StringStorage(newVals, size);
} else {
throw new UnexpectedTypeException("a Text column");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public long getItem(int idx) {

@Override
public double getItemDouble(int idx) {
return getItem(idx);
return (double) getItem(idx);
}

@Override
Expand Down Expand Up @@ -338,7 +338,7 @@ protected boolean doLong(long a, long b) {

@Override
protected boolean doDouble(long a, double b) {
return a > b;
return a < b;
}
})
.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.enso.table.data.column.operation.map.text.LikeOp;
import org.enso.table.data.column.operation.map.text.StringBooleanOp;
import org.enso.table.data.column.operation.map.text.StringIsInOp;
import org.enso.table.data.column.operation.map.text.StringStringOp;
import org.enso.table.data.column.storage.type.StorageType;
import org.enso.table.data.column.storage.type.TextType;
import org.graalvm.polyglot.Value;
Expand Down Expand Up @@ -139,6 +140,12 @@ protected boolean doString(String a, String b) {
});
t.add(new LikeOp());
t.add(new StringIsInOp<>());
t.add(new StringStringOp(Maps.ADD) {
@Override
protected String doString(String a, String b) {
return a + b;
}
});
return t;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec setup =
(x || Nothing).to_vector . should_equal nulls

Test.specify "should check types" <|
t = table_builder [["X", [1, 2, 3], ["Y", ['a', 'b', 'c']]], ["Z", [True, False, Nothing]]]
t = table_builder [["X", [1, 2, 3]], ["Y", ['a', 'b', 'c']], ["Z", [True, False, Nothing]]]

((t.at "X") && (t.at "Z")) . to_vector . should_fail_with Invalid_Value_Type
((t.at "Z") && (t.at "X")) . to_vector . should_fail_with Invalid_Value_Type
Expand Down Expand Up @@ -384,7 +384,7 @@ spec setup =
str.contains 42 . to_vector . should_fail_with Invalid_Value_Type

# Mixing text and integers should not be allowed
str + int . should_fail_with Illegal_Argument
(str + int) . should_fail_with Illegal_Argument

Test.specify "should return right types" <|
[Case_Sensitivity.Default, Case_Sensitivity.Sensitive, Case_Sensitivity.Insensitive].each cs->
Expand Down

0 comments on commit ab09a27

Please sign in to comment.