text: #include <gtest/gtest.h>
  #include <iostream>
  
  using namespace std;
  
  /**
   * This file is generated by leetcode_add.py v1.0
   *
   * 693.
   *      Binary Number with Alternating Bits
   *
   * ––––––––––––––––––––––––––––– Description –––––––––––––––––––––––––––––
   *
   *   Given a positive integer, check whether it has alternating bits:
   *   namely, if two adjacent bits will always have different values.
   *
   * ––––––––––––––––––––––––––––– Constraints –––––––––––––––––––––––––––––
   *
   *   • ‘1 ≤ n ≤ 2³¹ - 1’
   *
   */
  
  struct q693 : public ::testing::Test {
    // Leetcode answer here
    class Solution {
     public:
      bool hasAlternatingBits(int n) {
        bool prev = n & 1;
        n >>= 1;
        while (n != 0) {
          bool current = n & 1;
          if (prev == current) return false;
          prev = current;
          n >>= 1;
        }
        return true;
      }
    };
  
    class Solution *solution;
  };
  
  TEST_F(q693, sample_input01) {
    solution = new Solution();
    int n = 5;
    bool exp = true;
    EXPECT_EQ(solution->hasAlternatingBits(n), exp);
    delete solution;
  }
  
  TEST_F(q693, sample_input02) {
    solution = new Solution();
    int n = 7;
    bool exp = false;
    EXPECT_EQ(solution->hasAlternatingBits(n), exp);
    delete solution;
  }
  
  TEST_F(q693, sample_input03) {
    solution = new Solution();
    int n = 11;
    bool exp = false;
    EXPECT_EQ(solution->hasAlternatingBits(n), exp);
    delete solution;
  }
  
  TEST_F(q693, sample_input04) {
    solution = new Solution();
    int n = 10;
    bool exp = true;
    EXPECT_EQ(solution->hasAlternatingBits(n), exp);
    delete solution;
  }
  
  TEST_F(q693, sample_input05) {
    solution = new Solution();
    int n = 3;
    bool exp = false;
    EXPECT_EQ(solution->hasAlternatingBits(n), exp);
    delete solution;
  }