Skip to content

Commit

Permalink
Add sin expression
Browse files Browse the repository at this point in the history
Issue #72
  • Loading branch information
rakhimov committed Apr 25, 2017
1 parent c1af278 commit 511bddd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions share/input.rng
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,9 @@
<element name="cos">
<ref name="expression"/>
</element>
<element name="sin">
<ref name="expression"/>
</element>
</choice>
</define>

Expand Down
5 changes: 5 additions & 0 deletions src/expression/numerical.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ template <>
inline Interval GetInterval<Functor<&std::cos>>(Expression* /*arg*/) {
return Interval::closed(-1, 1);
}
template <>
inline Interval GetInterval<Functor<&std::sin>>(Expression* /*arg*/) {
return Interval::closed(-1, 1);
}
/// @}

using Neg = NaryExpression<std::negate<>, 1>; ///< Negation.
Expand All @@ -88,6 +92,7 @@ using Acos = FunctorExpression<&std::acos>; ///< Arc cosine.
using Asin = FunctorExpression<&std::asin>; ///< Arc sine.
using Atan = FunctorExpression<&std::atan>; ///< Arc tangent.
using Cos = FunctorExpression<&std::cos>; ///< Cosine.
using Sin = FunctorExpression<&std::sin>; ///< Sine.

} // namespace mef
} // namespace scram
Expand Down
3 changes: 2 additions & 1 deletion src/initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ const Initializer::ExtractorMap Initializer::kExpressionExtractors_ = {
{"acos", &Extract<Acos>},
{"asin", &Extract<Asin>},
{"atan", &Extract<Atan>},
{"cos", &Extract<Cos>}};
{"cos", &Extract<Cos>},
{"sin", &Extract<Sin>}};

Expression* Initializer::GetExpression(const xmlpp::Element* expr_element,
const std::string& base_path) {
Expand Down
11 changes: 11 additions & 0 deletions tests/expression_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,17 @@ TEST(ExpressionTest, Cos) {
EXPECT_TRUE(Interval::closed(-1, 1) == dev->interval()) << dev->interval();
}

TEST(ExpressionTest, Sin) {
OpenExpression arg_one(0);
std::unique_ptr<Expression> dev;
ASSERT_NO_THROW(dev = std::make_unique<Sin>(&arg_one));
EXPECT_DOUBLE_EQ(0, dev->value());
arg_one.mean = 0.5 * ConstantExpression::kPi.value();
EXPECT_DOUBLE_EQ(1, dev->value());

EXPECT_TRUE(Interval::closed(-1, 1) == dev->interval()) << dev->interval();
}

} // namespace test
} // namespace mef
} // namespace scram
5 changes: 5 additions & 0 deletions tests/input/fta/correct_expressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,10 @@ The input tries to utilize all the functionality including optional cases.
<float value="0"/>
</cos>
</define-parameter>
<define-parameter name="Sine">
<sin>
<float value="0"/>
</sin>
</define-parameter>
</model-data>
</opsa-mef>

0 comments on commit 511bddd

Please sign in to comment.