#!/bin/sh
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

set -eu

readonly TMP="$(mktemp -d)"
trap "rm -rf \"$TMP\"" EXIT
cd "$TMP"

cat >smoke.cc <<EOF
#include <gtest/gtest.h>
#include <wyhash/wyhash.h>

#include <string>

namespace {

TEST(WyhashTest, EmptyStringVector) {
  std::string vector;
  EXPECT_EQ(wyhash(vector.c_str(), vector.size(), 0, _wyp), 0x42bc986dc5eec4d3);
}

TEST(WyhashTest, SingleCharVector) {
  std::string vector = "a";
  EXPECT_EQ(wyhash(vector.c_str(), vector.size(), 1, _wyp), 0x84508dc903c31551);
}

TEST(WyhashTest, ShortStringVector) {
  std::string vector = "abc";
  EXPECT_EQ(wyhash(vector.c_str(), vector.size(), 2, _wyp), 0xbc54887cfc9ecb1);
}

TEST(WyhashTest, PhraseVector) {
  std::string vector = "message digest";
  EXPECT_EQ(wyhash(vector.c_str(), vector.size(), 3, _wyp), 0xadc146444841c430);
}

TEST(WyhashTest, AlphabetVector) {
  std::string vector = "abcdefghijklmnopqrstuvwxyz";
  EXPECT_EQ(wyhash(vector.c_str(), vector.size(), 4, _wyp), 0x4c0977bd4f14f34a);
}

TEST(WyhashTest, AsciiVector) {
  std::string vector =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  EXPECT_EQ(wyhash(vector.c_str(), vector.size(), 5, _wyp), 0x6f8bd609a8a276d2);
}

TEST(WyhashTest, DigitsVector) {
  std::string vector =
      "123456789012345678901234567890123456789012345678901234567890123456789012"
      "34567890";
  EXPECT_EQ(wyhash(vector.c_str(), vector.size(), 6, _wyp), 0x498d7c21668259ad);
}

}  // namespace
EOF

g++ -o smoke smoke.cc -lgtest -lgtest_main -pthread
./smoke
