1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef LIBTEXTCLASSIFIER_TESTS_FUNCTIONS_H_
18#define LIBTEXTCLASSIFIER_TESTS_FUNCTIONS_H_
19
20#include <math.h>
21
22#include "common/registry.h"
23
24namespace libtextclassifier {
25namespace nlp_core {
26namespace functions {
27// Abstract double -> double function.
28class Function : public RegisterableClass<Function> {
29 public:
30  virtual ~Function() {}
31  virtual double Evaluate(double x) = 0;
32};
33
34class Cos : public Function {
35 public:
36  double Evaluate(double x) override { return cos(x); }
37  TC_DEFINE_REGISTRATION_METHOD("cos", Cos);
38};
39
40class Exp : public Function {
41 public:
42  double Evaluate(double x) override { return exp(x); }
43  TC_DEFINE_REGISTRATION_METHOD("exp", Exp);
44};
45
46// Abstract int -> int function.
47class IntFunction : public RegisterableClass<IntFunction> {
48 public:
49  virtual ~IntFunction() {}
50  virtual int Evaluate(int k) = 0;
51};
52
53class Inc : public IntFunction {
54 public:
55  int Evaluate(int k) override { return k + 1; }
56  TC_DEFINE_REGISTRATION_METHOD("inc", Inc);
57};
58
59class Dec : public IntFunction {
60 public:
61  int Evaluate(int k) override { return k + 1; }
62  TC_DEFINE_REGISTRATION_METHOD("dec", Dec);
63};
64}  // namespace functions
65
66// Should be inside namespace libtextclassifier::nlp_core.
67TC_DECLARE_CLASS_REGISTRY_NAME(functions::Function);
68TC_DECLARE_CLASS_REGISTRY_NAME(functions::IntFunction);
69
70}  // namespace nlp_core
71}  // namespace libtextclassifier
72
73#endif  // LIBTEXTCLASSIFIER_TESTS_FUNCTIONS_H_
74