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

[Data] add data type u16 #844

Merged
merged 47 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ae5fab9
feat: add new data type u16
ChobobDev Sep 14, 2022
d9d36b5
feat: implement u16 in interval calculation
ChobobDev Sep 14, 2022
c34039b
feat: implement u16 in bigdecimal_ext
ChobobDev Sep 14, 2022
827f224
feat: implement U16 to keys
ChobobDev Sep 14, 2022
76dc4f2
test: initial test cases for u16
ChobobDev Sep 14, 2022
f29ff0e
test: fix misleading test cases
ChobobDev Sep 15, 2022
8de937a
feat: add U16 to binary operator
ChobobDev Sep 15, 2022
66133c4
Merge branch 'main' into feature/data_type_u16
ChobobDev Sep 16, 2022
f539bc3
feat: implement new data type u16
ChobobDev Sep 17, 2022
7ffd46a
Merge branch 'main' into feature/data_type_u16
ChobobDev Sep 17, 2022
678014f
Merge branch 'main' into feature/data_type_u16
ChobobDev Sep 17, 2022
58c5ad6
feat: add u16 rules
ChobobDev Sep 17, 2022
f81c788
fix: fix misleading typos
ChobobDev Sep 17, 2022
c6b550d
test: improve line coverage
ChobobDev Sep 17, 2022
3414b46
test: remove misleading test cases
ChobobDev Sep 17, 2022
b94f9a8
test: add new test cases to improve line coverage
ChobobDev Sep 17, 2022
68ff230
fix: add ommited datatype
ChobobDev Sep 17, 2022
af4a466
test: improve line coverage of convert.rs
ChobobDev Sep 17, 2022
c7249c8
test: improve line coverage of key.rs
ChobobDev Sep 17, 2022
e375b4d
test: improve line coverage in mod.rs
ChobobDev Sep 17, 2022
416faea
test: added omitted test cases of decimal.rs
ChobobDev Sep 17, 2022
4eb6675
test: improve line coverage of primitive.rs
ChobobDev Sep 17, 2022
4e9595f
test : improve line coverage of i8.rs
ChobobDev Sep 17, 2022
7efaf6a
test: add omitted test case
ChobobDev Sep 17, 2022
3791804
test: improve line coverage of u8.rs
ChobobDev Sep 17, 2022
8f38ebe
test: remove misleading test cases
ChobobDev Sep 17, 2022
9dcfda4
test: improve coverage of u8.rs
ChobobDev Sep 17, 2022
654d15c
test: add test cases for the u16.rs
ChobobDev Sep 17, 2022
1cdb23b
test: add omitted test cases
ChobobDev Sep 17, 2022
033a686
test: fix misleading test cases
ChobobDev Sep 17, 2022
165fbcf
test: add failing test case for implementing data type
ChobobDev Sep 30, 2022
ea2996b
test: add u16 to integration test
ChobobDev Sep 30, 2022
6a1725a
test: add new test cases to test negative arithemetics
ChobobDev Sep 30, 2022
66cb699
Merge branch 'main' into feature/data_type_u16
ChobobDev Sep 30, 2022
5446bf5
style: remove unnecessary function
ChobobDev Sep 30, 2022
48019db
test: comment unnecessary test cases
ChobobDev Oct 5, 2022
55ffa21
style: thanks to clippy
ChobobDev Oct 5, 2022
78bacee
Merge branch 'main' into feature/data_type_u16
ChobobDev Oct 5, 2022
3990ff8
Merge branch 'main' into feature/data_type_u16
ChobobDev Oct 14, 2022
f029df6
feat: new u16.rs that fits to macro test
ChobobDev Oct 14, 2022
eeb0eab
feat: implement u16 under integer directory
ChobobDev Oct 14, 2022
f76800c
Merge branch 'main' into feature/data_type_u16
ChobobDev Oct 22, 2022
f7cbde4
fix: fix misleading data type rules
ChobobDev Oct 22, 2022
af8ab13
fix: add ommited uint8 when merging
ChobobDev Oct 22, 2022
8a2f043
Merge branch 'main' into feature/data_type_u16
ChobobDev Oct 29, 2022
9495b78
fix: misleading import of macro
ChobobDev Oct 29, 2022
518a19f
test: remove redundant test cases
ChobobDev Oct 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add U16 to binary operator
  • Loading branch information
ChobobDev committed Sep 15, 2022
commit 8de937a9b46092a5696f9f67064ef1d532a6fb59
18 changes: 18 additions & 0 deletions core/src/data/value/binary_op/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl PartialEq<Value> for f64 {
I64(rhs) => (lhs - (rhs as f64)).abs() < f64::EPSILON,
I128(rhs) => (lhs - (rhs as f64)).abs() < f64::EPSILON,
U8(rhs) => (lhs - (rhs as f64)).abs() < f64::EPSILON,
U16(rhs) => (lhs - (rhs as f64)).abs() < f64::EPSILON,
F64(rhs) => (lhs - rhs).abs() < f64::EPSILON,
Decimal(rhs) => Decimal::from_f64_retain(lhs)
.map(|x| rhs == x)
Expand All @@ -39,6 +40,7 @@ impl PartialOrd<Value> for f64 {
I64(rhs) => self.partial_cmp(&(rhs as f64)),
I128(rhs) => self.partial_cmp(&(rhs as f64)),
U8(rhs) => self.partial_cmp(&(rhs as f64)),
U16(rhs) => self.partial_cmp(&(rhs as f64)),
F64(rhs) => self.partial_cmp(&rhs),
Decimal(rhs) => Decimal::from_f64_retain(*self)
.map(|x| x.partial_cmp(&rhs))
Expand All @@ -61,6 +63,7 @@ impl TryBinaryOperator for f64 {
I64(rhs) => Ok(F64(lhs + rhs as f64)),
I128(rhs) => Ok(F64(lhs + rhs as f64)),
U8(rhs) => Ok(F64(lhs + rhs as f64)),
U16(rhs) => Ok(F64(lhs + rhs as f64)),
F64(rhs) => Ok(F64(lhs + rhs)),
Decimal(rhs) => Decimal::from_f64_retain(lhs)
.map(|x| Ok(Decimal(x + rhs)))
Expand All @@ -85,6 +88,7 @@ impl TryBinaryOperator for f64 {
I64(rhs) => Ok(F64(lhs - rhs as f64)),
I128(rhs) => Ok(F64(lhs - rhs as f64)),
U8(rhs) => Ok(F64(lhs - rhs as f64)),
U16(rhs) => Ok(F64(lhs - rhs as f64)),
F64(rhs) => Ok(F64(lhs - rhs)),
Decimal(rhs) => Decimal::from_f64_retain(lhs)
.map(|x| Ok(Decimal(x - rhs)))
Expand All @@ -109,6 +113,7 @@ impl TryBinaryOperator for f64 {
I64(rhs) => Ok(F64(lhs * rhs as f64)),
I128(rhs) => Ok(F64(lhs * rhs as f64)),
U8(rhs) => Ok(F64(lhs * rhs as f64)),
U16(rhs) => Ok(F64(lhs * rhs as f64)),
F64(rhs) => Ok(F64(lhs * rhs)),
Interval(rhs) => Ok(Interval(lhs * rhs)),
Decimal(rhs) => Decimal::from_f64_retain(lhs)
Expand All @@ -134,6 +139,7 @@ impl TryBinaryOperator for f64 {
I64(rhs) => Ok(F64(lhs / rhs as f64)),
I128(rhs) => Ok(F64(lhs / rhs as f64)),
U8(rhs) => Ok(F64(lhs / rhs as f64)),
U16(rhs) => Ok(F64(lhs / rhs as f64)),
F64(rhs) => Ok(F64(lhs / rhs)),
Decimal(rhs) => Decimal::from_f64_retain(lhs)
.map(|x| Ok(Decimal(x * rhs)))
Expand All @@ -158,6 +164,7 @@ impl TryBinaryOperator for f64 {
I64(rhs) => Ok(F64(lhs % rhs as f64)),
I128(rhs) => Ok(F64(lhs % rhs as f64)),
U8(rhs) => Ok(F64(lhs % rhs as f64)),
U16(rhs) => Ok(F64(lhs % rhs as f64)),
F64(rhs) => Ok(F64(lhs % rhs)),
Decimal(rhs) => match Decimal::from_f64_retain(lhs) {
Some(x) => x
Expand Down Expand Up @@ -203,6 +210,7 @@ mod tests {
assert_eq!(base, I64(1));
assert_eq!(base, I128(1));
assert_eq!(base, U8(1));
assert_eq!(base, U16(1));
assert_eq!(base, F64(1.0));
assert_eq!(base, Decimal(Decimal::from(1)));

Expand All @@ -219,6 +227,7 @@ mod tests {
assert_eq!(base.partial_cmp(&I64(1)), Some(Ordering::Equal));
assert_eq!(base.partial_cmp(&I128(1)), Some(Ordering::Equal));
assert_eq!(base.partial_cmp(&U8(1)), Some(Ordering::Equal));
assert_eq!(base.partial_cmp(&U16(1)), Some(Ordering::Equal));
assert_eq!(base.partial_cmp(&F64(1.0)), Some(Ordering::Equal));
assert_eq!(
base.partial_cmp(&Decimal(Decimal::ONE)),
Expand All @@ -238,6 +247,7 @@ mod tests {
assert!(matches!(base.try_add(&I64(1)), Ok(F64(x)) if (x - 2.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_add(&I128(1)), Ok(F64(x)) if (x - 2.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_add(&U8(1)), Ok(F64(x)) if (x - 2.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_add(&U16(1)), Ok(F64(x)) if (x - 2.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_add(&F64(1.0)), Ok(F64(x)) if (x - 2.0).abs() < f64::EPSILON ));
assert!(
matches!(base.try_add(&Decimal(Decimal::ONE)), Ok(Decimal(x)) if x == Decimal::TWO)
Expand Down Expand Up @@ -272,6 +282,9 @@ mod tests {
matches!(base.try_subtract(&I128(1)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON )
);
assert!(matches!(base.try_subtract(&U8(1)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON ));
assert!(
matches!(base.try_subtract(&U16(1)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON )
);
assert!(
matches!(base.try_subtract(&F64(1.0)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON )
);
Expand Down Expand Up @@ -308,6 +321,9 @@ mod tests {
matches!(base.try_multiply(&I128(1)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON )
);
assert!(matches!(base.try_multiply(&U8(1)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON ));
assert!(
matches!(base.try_multiply(&U16(1)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON )
);
assert!(
matches!(base.try_multiply(&F64(1.0)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON )
);
Expand Down Expand Up @@ -336,6 +352,7 @@ mod tests {
assert!(matches!(base.try_divide(&I64(1)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_divide(&I128(1)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_divide(&U8(1)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_divide(&U16(1)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON ));
assert!(
matches!(base.try_divide(&F64(1.0)), Ok(F64(x)) if (x - 1.0).abs() < f64::EPSILON )
);
Expand Down Expand Up @@ -364,6 +381,7 @@ mod tests {
assert!(matches!(base.try_modulo(&I64(1)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_modulo(&I128(1)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_modulo(&U8(1)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON ));
assert!(matches!(base.try_modulo(&U16(1)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON ));
assert!(
matches!(base.try_modulo(&F64(1.0)), Ok(F64(x)) if (x - 0.0).abs() < f64::EPSILON )
);
Expand Down
13 changes: 13 additions & 0 deletions core/src/data/value/binary_op/i128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl PartialEq<Value> for i128 {
I64(other) => self == &(*other as i128),
I128(other) => self == other,
U8(other) => self == &(*other as i128),
U16(other) => self == &(*other as i128),
F64(other) => ((*self as f64) - other).abs() < f64::EPSILON,
Decimal(other) => Decimal::from(*self) == *other,
_ => false,
Expand All @@ -35,6 +36,7 @@ impl PartialOrd<Value> for i128 {
I64(other) => PartialOrd::partial_cmp(self, &(*other as i128)),
I128(other) => PartialOrd::partial_cmp(self, other),
U8(other) => PartialOrd::partial_cmp(self, &(*other as i128)),
U16(other) => PartialOrd::partial_cmp(self, &(*other as i128)),
F64(other) => PartialOrd::partial_cmp(&(*self as f64), other),
Decimal(other) => Decimal::from(*self).partial_cmp(other),
_ => None,
Expand Down Expand Up @@ -116,6 +118,17 @@ impl TryBinaryOperator for i128 {
.into()
})
.map(I128),
U16(rhs) => lhs
.checked_add(rhs as i128)
.ok_or_else(|| {
ValueError::BinaryOperationOverflow {
lhs: I128(lhs),
rhs: U16(rhs),
operator: NumericBinaryOperator::Add,
}
.into()
})
.map(I128),
F64(rhs) => Ok(F64(lhs as f64 + rhs)),
Decimal(rhs) => Ok(Decimal(Decimal::from(lhs) + rhs)),
Null => Ok(Null),
Expand Down
57 changes: 57 additions & 0 deletions core/src/data/value/binary_op/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl PartialEq<Value> for i16 {
I64(rhs) => (lhs as i64) == *rhs,
I128(rhs) => (lhs as i128) == *rhs,
U8(rhs) => lhs == (*rhs as i16),
U16(rhs) => lhs == (*rhs as i16),
F64(rhs) => ((lhs as f64) - rhs).abs() < f64::EPSILON,
Decimal(rhs) => Decimal::from(lhs) == *rhs,
_ => false,
Expand All @@ -37,6 +38,7 @@ impl PartialOrd<Value> for i16 {
I64(rhs) => (*self as i64).partial_cmp(rhs),
I128(rhs) => (*self as i128).partial_cmp(rhs),
U8(rhs) => self.partial_cmp(&(*rhs as i16)),
U16(rhs) => self.partial_cmp(&(*rhs as i16)),
F64(rhs) => (*self as f64).partial_cmp(rhs),
Decimal(rhs) => Decimal::from(*self).partial_cmp(rhs),
_ => None,
Expand Down Expand Up @@ -117,6 +119,17 @@ impl TryBinaryOperator for i16 {
.into()
})
.map(I16),
U16(rhs) => lhs
.checked_add(rhs as i16)
.ok_or_else(|| {
ValueError::BinaryOperationOverflow {
lhs: I16(lhs),
rhs: U16(rhs),
operator: NumericBinaryOperator::Add,
}
.into()
})
.map(I16),
F64(rhs) => Ok(F64(lhs as f64 + rhs)),
Decimal(rhs) => Ok(Decimal(Decimal::from(lhs) + rhs)),
Null => Ok(Null),
Expand Down Expand Up @@ -199,6 +212,17 @@ impl TryBinaryOperator for i16 {
.into()
})
.map(I16),
U16(rhs) => lhs
.checked_sub(rhs as i16)
.ok_or_else(|| {
ValueError::BinaryOperationOverflow {
lhs: I16(lhs),
rhs: U16(rhs),
operator: NumericBinaryOperator::Subtract,
}
.into()
})
.map(I16),
F64(rhs) => Ok(F64(lhs as f64 - rhs)),
Decimal(rhs) => Decimal::from(lhs)
.checked_sub(rhs)
Expand Down Expand Up @@ -291,6 +315,17 @@ impl TryBinaryOperator for i16 {
.into()
})
.map(I16),
U16(rhs) => lhs
.checked_mul(rhs as i16)
.ok_or_else(|| {
ValueError::BinaryOperationOverflow {
lhs: I16(lhs),
rhs: U16(rhs),
operator: NumericBinaryOperator::Multiply,
}
.into()
})
.map(I16),
F64(rhs) => Ok(F64(lhs as f64 * rhs)),
Decimal(rhs) => Decimal::from(lhs)
.checked_mul(rhs)
Expand Down Expand Up @@ -384,6 +419,17 @@ impl TryBinaryOperator for i16 {
.into()
})
.map(I16),
U16(rhs) => lhs
.checked_div(rhs as i16)
.ok_or_else(|| {
ValueError::BinaryOperationOverflow {
lhs: I16(lhs),
rhs: U16(rhs),
operator: NumericBinaryOperator::Divide,
}
.into()
})
.map(I16),
F64(rhs) => Ok(F64(lhs as f64 / rhs)),
Decimal(rhs) => Decimal::from(lhs)
.checked_div(rhs)
Expand Down Expand Up @@ -476,6 +522,17 @@ impl TryBinaryOperator for i16 {
.into()
})
.map(I16),
U16(rhs) => lhs
.checked_rem(rhs as i16)
.ok_or_else(|| {
ValueError::BinaryOperationOverflow {
lhs: I16(lhs),
rhs: U16(rhs),
operator: NumericBinaryOperator::Modulo,
}
.into()
})
.map(I16),
F64(rhs) => Ok(F64(lhs as f64 % rhs)),
Decimal(rhs) => Decimal::from(lhs)
.checked_rem(rhs)
Expand Down
1 change: 1 addition & 0 deletions core/src/data/value/binary_op/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod i16;
mod i32;
mod i64;
mod i8;
mod u16;
mod u8;

pub trait TryBinaryOperator {
Expand Down