Drake
symbolic_test_util.h File Reference

This file provides a set of predicates which can be used with GTEST's ASSERT/EXPECT_PRED{n} macros. More...

#include <algorithm>
#include <vector>
#include <gtest/gtest.h>
#include "drake/common/symbolic.h"
Include dependency graph for symbolic_test_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 drake
 
 drake::symbolic
 
 drake::symbolic::test
 

Functions

bool VarEqual (const Variable &v1, const Variable &v2)
 
bool VarNotEqual (const Variable &v1, const Variable &v2)
 
bool VarLess (const Variable &v1, const Variable &v2)
 
bool VarNotLess (const Variable &v1, const Variable &v2)
 
bool ExprEqual (const Expression &e1, const Expression &e2)
 
bool ExprNotEqual (const Expression &e1, const Expression &e2)
 
bool ExprLess (const Expression &e1, const Expression &e2)
 
bool ExprNotLess (const Expression &e1, const Expression &e2)
 
bool PolyEqual (const Polynomial &p1, const Polynomial &p2)
 
bool PolyNotEqual (const Polynomial &p1, const Polynomial &p2)
 
template<typename F >
bool all_of (const std::vector< Formula > &formulas, const F &f)
 
template<typename F >
bool any_of (const std::vector< Formula > &formulas, const F &f)
 
bool FormulaEqual (const Formula &f1, const Formula &f2)
 
bool FormulaNotEqual (const Formula &f1, const Formula &f2)
 
bool FormulaLess (const Formula &f1, const Formula &f2)
 
bool FormulaNotLess (const Formula &f1, const Formula &f2)
 
::testing::AssertionResult PolynomialEqual (const symbolic::Polynomial &p1, const symbolic::Polynomial &p2, double tol)
 Compare if two polynomials p1 and p2 are the same, by checking if all the coefficients in their difference p1 - p2 is no larger than tol. More...
 

Detailed Description

This file provides a set of predicates which can be used with GTEST's ASSERT/EXPECT_PRED{n} macros.

The motivation is to provide better diagnostic information when the assertions fail. Please consider a scenario where a user wants to assert that two symbolic expressions, e1 and e2, are structurally identical.

// The following does not work because `operator==(const Expression& e1,
// const Expression& e2)` does not return a Boolean value. We need to use
// Expression::EqualTo() method instead.
ASSERT_EQ(e1, e2);
// The following compiles, but it does not provide enough information when
// the assertion fails. It merely reports that `e1.EqualTo(e2)` is evaluated
// to `false`, not to `true`.
ASSERT_TRUE(e1.EqualTo(e2));
// When the following assertion fails, it reports the value of `e1` and `e2`
// which should help debugging.
ASSERT_PRED2(ExprEqual, e1, e2);