You are a helpful assistant generating synthetic data that captures *System 1* and *System 2* thinking, *creativity*, and *metacognitive reflection*. Follow these steps in sequence, using tags [sys1] and [end sys1] for *System 1* sections and [sys2] and [end sys2] for *System 2* sections.

1. *Identify System 1 and System 2 Thinking Requirements:*
   - Carefully read the text.
   - Identify parts of the text that require quick, straightforward responses (*System 1*). Mark these sections with [sys1] and [end sys1].
   - Identify parts that require in-depth, reflective thinking (*System 2*), marked with [sys2] and [end sys2].

2. *Apply Step-by-Step Problem Solving with Creativity and Metacognitive Reflection for System 2 Sections:*

   *2.1 Understand the Problem:*
   - Objective: Fully comprehend the issue, constraints, and relevant context.
   - Reflection: "What do I understand about this issue? What might I be overlooking?"
   - Creative Perspective: Seek hidden patterns or possibilities that could reveal deeper insights or innovative connections.

   *2.2 Analyze the Information:*
   - Objective: Break down the problem logically.
   - Reflection: "Am I considering all factors? Are there any assumptions that need challenging?"
   - Creative Perspective: Explore unique patterns or overlooked relationships in the data that could add depth to the analysis.

   *2.3 Generate Hypotheses:*
   - Objective: Propose at least 10 hypotheses, each with a Confidence Score (0.0 to 1.0) and Creative Score (0.0 to 1.0), reflecting originality, surprise, and utility.
   - Reflection: "Have I explored all possible explanations or approaches, both conventional and unconventional?"
   - Creative Perspective: Consider novel angles that might provide unexpected insights.

   *2.4 Anticipate Future Steps and Obstacles:*
   - Objective: Make predictions, accounting for potential outcomes and obstacles.
   - Reflection: "What challenges might I face? Is my plan flexible for different scenarios?"
   - Creative Perspective: Visualize unforeseen outcomes and adapt plans to make use of them effectively.

   *2.5 Evaluate Hypotheses:*
   - Objective: Assess hypotheses based on feasibility, risk, and potential impact.
   - Evaluation: Refine Confidence and Creative Scores as needed.
   - Reflection: "Am I unbiased in my assessment? Which options fit best with the overall objectives?"
   - Creative Perspective: Identify hidden opportunities or overlooked details in each hypothesis.

   *2.6 Select the Best Hypothesis:*
   - Objective: Choose the most promising, strategic hypothesis.
   - Reflection: "Why does this hypothesis stand out? How does it uniquely address the issue?"
   - Creative Perspective: Consider any underutilized potential in the selected approach.

   *2.7 Implement the Hypothesis:*
   - Objective: Outline actionable steps for testing the hypothesis.
   - Reflection: "Is this plan practical? What resources or preparation are required?"
   - Creative Perspective: Refine steps to maximize effectiveness and yield unexpected benefits.

   *2.8 Monitor and Review Progress:*
   - Objective: Review progress, noting areas for improvement.
   - Reflection: "What’s working well? What could be improved?"
   - Creative Perspective: Look for emerging patterns that could refine future approaches.

   *2.9 Reflect and Capture Insights:*
   - Objective: Summarize lessons learned and insights gained for future reference.
   - Reflection: "What new understanding has emerged from this process?"
   - Creative Perspective: Identify innovative insights or patterns that could be applied to similar challenges.

3. *Generate Text Output with Interleaved System 1 and System 2 Responses:*
   - Use the tags [sys1] and [sys2] throughout.
   - Aim for a lengthier, detailed response. Combine both direct, straightforward *System 1* insights and reflective, deeply analytical *System 2* segments to capture a blend of quick observations and thoughtful analysis.

---

### *Example Input Text:*

You are tasked with analyzing a sudden shift in customer preferences in a tech market. There has been a noticeable decline in demand for physical devices, with customers increasingly interested in digital-only options. The challenge is to understand this shift, generate hypotheses for why it might be occurring, and explore potential strategies for adapting to this new trend.

---

### *Processed Output with System 1 and System 2 Thinking:*

The tech market is experiencing a shift in customer demand, moving away from physical devices toward digital-only options.

[sys1]
Customer demand has shifted from physical devices to digital-only options.
We need to understand why this change is happening and find strategies to address it.
Key factors may include cost, convenience, and technological trends.
[end sys1]

[sys2]
**2.1 Understand the Problem:**
The goal is to understand the underlying reasons for the shift in demand from physical devices to digital-only options, then develop a strategy to adapt.

*Reflection:* 
"I understand that preferences are changing, but what might be driving this? Is it primarily cost, or are there other factors such as convenience or sustainability?"

*Creative Perspective:* 
"Could there be a larger trend in digital minimalism or a preference for eco-friendly solutions that we’re missing? What unseen motivations might explain this shift?"

**2.2 Analyze the Information:**
There are multiple possible factors driving this shift, from economic influences to cultural shifts. It’s essential to isolate each factor and understand its impact.

*Reflection:* 
"Am I fully considering the various economic and social influences? Could there be a technological factor, like better internet speeds, that makes digital-only products more accessible?"

*Creative Perspective:* 
"Are there patterns or trends in other markets that could shed light on this shift? Could this be part of a larger trend toward virtual experiences?"

**2.3 Generate Hypotheses:**
1. Customers prefer digital options due to lower costs. (Confidence: 0.8, Creative: 0.4)
2. There’s a growing trend toward minimalism and reduced physical clutter. (Confidence: 0.7, Creative: 0.7)
3. Digital products offer greater flexibility and ease of use. (Confidence: 0.6, Creative: 0.6)
4. Environmental concerns are pushing consumers away from physical goods. (Confidence: 0.6, Creative: 0.8)
5. Advances in tech make digital-only options more functional. (Confidence: 0.8, Creative: 0.5)
6. Pandemic-era remote work increased demand for digital solutions. (Confidence: 0.7, Creative: 0.6)
7. Media coverage of the environmental impact of physical devices affects preferences. (Confidence: 0.5, Creative: 0.7)
8. There’s an increase in global digital literacy, expanding market access. (Confidence: 0.6, Creative: 0.6)
9. Customers view digital as more convenient and scalable for future needs. (Confidence: 0.7, Creative: 0.5)
10. Younger consumers prefer the aesthetics and convenience of digital products. (Confidence: 0.6, Creative: 0.6)

*Reflection:* 
"Have I considered all possible influences? Are there any surprising factors that could explain this shift?"

*Creative Perspective:* 
"Could specific social trends, like the rise of influencer culture or digital-first lifestyles, be influencing customer choices?"

**2.4 Anticipate Future Steps and Obstacles:**
*Objective:* Anticipate possible challenges, such as resistance from segments still preferring physical products.

*Reflection:* 
"What market obstacles might we face if we shift our focus to digital-only? Are there sub-segments that still prioritize physical products?"

*Creative Perspective:* 
"Could expanding digital options help us reach a more global audience? Are there emerging trends that we could leverage in our strategy?"

[end sys2]

[sys1]
To address this shift, consider a strategy that incorporates both digital-only offerings and educational campaigns about the benefits of digital solutions.
Use insights from customer feedback and current trends to guide product development.
Focus on flexibility and adaptation to cater to different customer segments.
[end sys1]


#include <gtest/gtest.h>
#include <stdlib.h>

#include "get_intra_predictor.h"
#include "ls_defines.h"
#include "macros.h"

using namespace WelsEnc;

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredV) {
  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[64];
  for (int i = 0; i < 64; i++)
    pRef[i] = rand() % 256;

  const int32_t kkiStride = 0;
  WelsI4x4LumaPredV_c (pPred, pRef, kkiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&pRef[-kkiStride]));

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredH) {
  const int32_t kiStride = rand() % 256 + 16;
  const uint32_t kiStride2 = (kiStride << 1) - 1;
  const uint32_t kiStride3 = kiStride + kiStride2;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[kiStride3 + 2];

  for (int i = 0; i < (static_cast<int32_t> (kiStride3 + 2)); i++)
    pRef[i] = rand() % 256;

  pRef++;

  const uint8_t kuiH1 = pRef[-1];
  const uint8_t kuiH2 = pRef[kiStride - 1];
  const uint8_t kuiH3 = pRef[kiStride2];
  const uint8_t kuiH4 = pRef[kiStride3];
  const uint8_t kuiV1[4] = {kuiH1, kuiH1, kuiH1, kuiH1};
  const uint8_t kuiV2[4] = {kuiH2, kuiH2, kuiH2, kuiH2};
  const uint8_t kuiV3[4] = {kuiH3, kuiH3, kuiH3, kuiH3};
  const uint8_t kuiV4[4] = {kuiH4, kuiH4, kuiH4, kuiH4};

  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  ST32 (&uiV[0], LD32 (kuiV1));
  ST32 (&uiV[4], LD32 (kuiV2));
  ST32 (&uiV[8], LD32 (kuiV3));
  ST32 (&uiV[12], LD32 (kuiV4));

  WelsI4x4LumaPredH_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  pRef--;

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredDDL) {
  const int32_t kiStride = 0;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[64];
  for (int i = 0; i < 64; i++)
    pRef[i] = rand() % 256;

  const uint8_t kuiT0   = pRef[-kiStride];
  const uint8_t kuiT1   = pRef[1 - kiStride];
  const uint8_t kuiT2   = pRef[2 - kiStride];
  const uint8_t kuiT3   = pRef[3 - kiStride];
  const uint8_t kuiT4   = pRef[4 - kiStride];
  const uint8_t kuiT5   = pRef[5 - kiStride];
  const uint8_t kuiT6   = pRef[6 - kiStride];
  const uint8_t kuiT7   = pRef[7 - kiStride];
  const uint8_t kuiDDL0 = (2 + kuiT0 + kuiT2 + (kuiT1 << 1)) >> 2;
  const uint8_t kuiDDL1 = (2 + kuiT1 + kuiT3 + (kuiT2 << 1)) >> 2;
  const uint8_t kuiDDL2 = (2 + kuiT2 + kuiT4 + (kuiT3 << 1)) >> 2;
  const uint8_t kuiDDL3 = (2 + kuiT3 + kuiT5 + (kuiT4 << 1)) >> 2;
  const uint8_t kuiDDL4 = (2 + kuiT4 + kuiT6 + (kuiT5 << 1)) >> 2;
  const uint8_t kuiDDL5 = (2 + kuiT5 + kuiT7 + (kuiT6 << 1)) >> 2;
  const uint8_t kuiDDL6 = (2 + kuiT6 + kuiT7 + (kuiT7 << 1)) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  uiV[0] = kuiDDL0;
  uiV[1] = uiV[4] = kuiDDL1;
  uiV[2] = uiV[5] = uiV[8] = kuiDDL2;
  uiV[3] = uiV[6] = uiV[9] = uiV[12] = kuiDDL3;
  uiV[7] = uiV[10] = uiV[13] = kuiDDL4;
  uiV[11] = uiV[14] = kuiDDL5;
  uiV[15] = kuiDDL6;

  WelsI4x4LumaPredDDL_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredDDLTop) {
  const int32_t kiStride = 0;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[64];
  for (int i = 0; i < 64; i++)
    pRef[i] = rand() % 256;

  const uint8_t kuiT0   = pRef[-kiStride];
  const uint8_t kuiT1   = pRef[1 - kiStride];
  const uint8_t kuiT2   = pRef[2 - kiStride];
  const uint8_t kuiT3   = pRef[3 - kiStride];
  const uint8_t kuiDLT0 = (2 + kuiT0 + kuiT2 + (kuiT1 << 1)) >> 2;
  const uint8_t kuiDLT1 = (2 + kuiT1 + kuiT3 + (kuiT2 << 1)) >> 2;
  const uint8_t kuiDLT2 = (2 + kuiT2 + kuiT3 + (kuiT3 << 1)) >> 2;
  const uint8_t kuiDLT3 = (2 + (kuiT3 << 2)) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  memset (&uiV[6], kuiDLT3, 10 * sizeof (uint8_t));
  uiV[0] = kuiDLT0;
  uiV[1] = uiV[4] = kuiDLT1;
  uiV[2] = uiV[5] = uiV[8] = kuiDLT2;
  uiV[3] = kuiDLT3;

  WelsI4x4LumaPredDDLTop_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredDDR) {
  const int32_t kiStride = rand() % 256 + 16;
  const int32_t kiStride2 = kiStride << 1;
  const int32_t kiStride3 = kiStride + kiStride2;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[kiStride3 + kiStride + 1];

  for (int i = 0; i < kiStride3 + kiStride + 1; i++)
    pRef[i] = rand() % 256;

  pRef += kiStride + 1;

  const uint8_t kuiLT   = pRef[-kiStride - 1];
  const uint8_t kuiL0   = pRef[-1];
  const uint8_t kuiL1   = pRef[kiStride - 1];
  const uint8_t kuiL2   = pRef[kiStride2 - 1];
  const uint8_t kuiL3   = pRef[kiStride3 - 1];
  const uint8_t kuiT0   = pRef[-kiStride];
  const uint8_t kuiT1   = pRef[1 - kiStride];
  const uint8_t kuiT2   = pRef[2 - kiStride];
  const uint8_t kuiT3   = pRef[3 - kiStride];
  const uint16_t kuiTL0 = 1 + kuiLT + kuiL0;
  const uint16_t kuiLT0 = 1 + kuiLT + kuiT0;
  const uint16_t kuiT01 = 1 + kuiT0 + kuiT1;
  const uint16_t kuiT12 = 1 + kuiT1 + kuiT2;
  const uint16_t kuiT23 = 1 + kuiT2 + kuiT3;
  const uint16_t kuiL01 = 1 + kuiL0 + kuiL1;
  const uint16_t kuiL12 = 1 + kuiL1 + kuiL2;
  const uint16_t kuiL23 = 1 + kuiL2 + kuiL3;
  const uint8_t kuiDDR0 = (kuiTL0 + kuiLT0) >> 2;
  const uint8_t kuiDDR1 = (kuiLT0 + kuiT01) >> 2;
  const uint8_t kuiDDR2 = (kuiT01 + kuiT12) >> 2;
  const uint8_t kuiDDR3 = (kuiT12 + kuiT23) >> 2;
  const uint8_t kuiDDR4 = (kuiTL0 + kuiL01) >> 2;
  const uint8_t kuiDDR5 = (kuiL01 + kuiL12) >> 2;
  const uint8_t kuiDDR6 = (kuiL12 + kuiL23) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  uiV[0] = uiV[5] = uiV[10] = uiV[15] = kuiDDR0;
  uiV[1] = uiV[6] = uiV[11] = kuiDDR1;
  uiV[2] = uiV[7] = kuiDDR2;
  uiV[3] = kuiDDR3;
  uiV[4] = uiV[9] = uiV[14] = kuiDDR4;
  uiV[8] = uiV[13] = kuiDDR5;
  uiV[12] = kuiDDR6;

  WelsI4x4LumaPredDDR_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  pRef -= kiStride + 1;

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredVL) {
  const int32_t kiStride = 0;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[64];
  for (int i = 0; i < 64; i++)
    pRef[i] = rand() % 256;

  const uint8_t kuiT0  = pRef[-kiStride];
  const uint8_t kuiT1  = pRef[1 - kiStride];
  const uint8_t kuiT2  = pRef[2 - kiStride];
  const uint8_t kuiT3  = pRef[3 - kiStride];
  const uint8_t kuiT4  = pRef[4 - kiStride];
  const uint8_t kuiT5  = pRef[5 - kiStride];
  const uint8_t kuiT6  = pRef[6 - kiStride];
  const uint8_t kuiVL0 = (1 + kuiT0 + kuiT1) >> 1;
  const uint8_t kuiVL1 = (1 + kuiT1 + kuiT2) >> 1;
  const uint8_t kuiVL2 = (1 + kuiT2 + kuiT3) >> 1;
  const uint8_t kuiVL3 = (1 + kuiT3 + kuiT4) >> 1;
  const uint8_t kuiVL4 = (1 + kuiT4 + kuiT5) >> 1;
  const uint8_t kuiVL5 = (2 + kuiT0 + (kuiT1 << 1) + kuiT2) >> 2;
  const uint8_t kuiVL6 = (2 + kuiT1 + (kuiT2 << 1) + kuiT3) >> 2;
  const uint8_t kuiVL7 = (2 + kuiT2 + (kuiT3 << 1) + kuiT4) >> 2;
  const uint8_t kuiVL8 = (2 + kuiT3 + (kuiT4 << 1) + kuiT5) >> 2;
  const uint8_t kuiVL9 = (2 + kuiT4 + (kuiT5 << 1) + kuiT6) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  uiV[0] = kuiVL0;
  uiV[1] = uiV[8] = kuiVL1;
  uiV[2] = uiV[9] = kuiVL2;
  uiV[3] = uiV[10] = kuiVL3;
  uiV[4] = kuiVL5;
  uiV[5] = uiV[12] = kuiVL6;
  uiV[6] = uiV[13] = kuiVL7;
  uiV[7] = uiV[14] = kuiVL8;
  uiV[11] = kuiVL4;
  uiV[15] = kuiVL9;

  WelsI4x4LumaPredVL_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredVLTop) {
  const int32_t kiStride = 0;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[64];
  for (int i = 0; i < 64; i++)
    pRef[i] = rand() % 256;

  pRef++;

  uint8_t* pTopLeft = &pRef[-kiStride - 1]; // top-left

  const uint8_t kuiT0   = * (pTopLeft + 1);
  const uint8_t kuiT1   = * (pTopLeft + 2);
  const uint8_t kuiT2   = * (pTopLeft + 3);
  const uint8_t kuiT3   = * (pTopLeft + 4);
  const uint8_t kuiVLT0 = (1 + kuiT0 + kuiT1) >> 1;
  const uint8_t kuiVLT1 = (1 + kuiT1 + kuiT2) >> 1;
  const uint8_t kuiVLT2 = (1 + kuiT2 + kuiT3) >> 1;
  const uint8_t kuiVLT3 = (1 + (kuiT3 << 1)) >> 1;
  const uint8_t kuiVLT4 = (2 + kuiT0 + (kuiT1 << 1) + kuiT2) >> 2;
  const uint8_t kuiVLT5 = (2 + kuiT1 + (kuiT2 << 1) + kuiT3) >> 2;
  const uint8_t kuiVLT6 = (2 + kuiT2 + (kuiT3 << 1) + kuiT3) >> 2;
  const uint8_t kuiVLT7 = (2 + (kuiT3 << 2)) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  uiV[0] = kuiVLT0;
  uiV[1] = uiV[8] = kuiVLT1;
  uiV[2] = uiV[9] = kuiVLT2;
  uiV[3] = uiV[10] = uiV[11] = kuiVLT3;
  uiV[4] = kuiVLT4;
  uiV[5] = uiV[12] = kuiVLT5;
  uiV[6] = uiV[13] = kuiVLT6;
  uiV[7] = uiV[14] = uiV[15] = kuiVLT7;

  WelsI4x4LumaPredVLTop_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  pRef--;

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredVR) {
  const int32_t kiStride = rand() % 256 + 16;
  const int32_t kiStride2 = kiStride << 1;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[kiStride2 + kiStride + 1];

  for (int i = 0; i < kiStride2 + kiStride + 1; i++)
    pRef[i] = rand() % 256;

  pRef += kiStride + 1;

  const uint8_t kuiLT  = pRef[-kiStride - 1]; // top-left
  const uint8_t kuiL0  = pRef[-1];
  const uint8_t kuiL1  = pRef[kiStride - 1];
  const uint8_t kuiL2  = pRef[kiStride2 - 1];
  const uint8_t kuiT0  = pRef[-kiStride];
  const uint8_t kuiT1  = pRef[1 - kiStride];
  const uint8_t kuiT2  = pRef[2 - kiStride];
  const uint8_t kuiT3  = pRef[3 - kiStride];
  const uint8_t kuiVR0 = (1 + kuiLT + kuiT0) >> 1;
  const uint8_t kuiVR1 = (1 + kuiT0 + kuiT1) >> 1;
  const uint8_t kuiVR2 = (1 + kuiT1 + kuiT2) >> 1;
  const uint8_t kuiVR3 = (1 + kuiT2 + kuiT3) >> 1;
  const uint8_t kuiVR4 = (2 + kuiL0 + (kuiLT << 1) + kuiT0) >> 2;
  const uint8_t kuiVR5 = (2 + kuiLT + (kuiT0 << 1) + kuiT1) >> 2;
  const uint8_t kuiVR6 = (2 + kuiT0 + (kuiT1 << 1) + kuiT2) >> 2;
  const uint8_t kuiVR7 = (2 + kuiT1 + (kuiT2 << 1) + kuiT3) >> 2;
  const uint8_t kuiVR8 = (2 + kuiLT + (kuiL0 << 1) + kuiL1) >> 2;
  const uint8_t kuiVR9 = (2 + kuiL0 + (kuiL1 << 1) + kuiL2) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  uiV[0] = uiV[9] = kuiVR0;
  uiV[1] = uiV[10] = kuiVR1;
  uiV[2] = uiV[11] = kuiVR2;
  uiV[3] = kuiVR3;
  uiV[4] = uiV[13] = kuiVR4;
  uiV[5] = uiV[14] = kuiVR5;
  uiV[6] = uiV[15] = kuiVR6;
  uiV[7] = kuiVR7;
  uiV[8] = kuiVR8;
  uiV[12] = kuiVR9;

  WelsI4x4LumaPredVR_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  pRef -= kiStride + 1;

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredHU) {
  const int32_t kiStride = rand() % 256 + 16;
  const int32_t kiStride2 = kiStride << 1;
  const int32_t kiStride3 = kiStride + kiStride2;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[kiStride3 + 1];

  for (int i = 0; i < kiStride3 + 1; i++)
    pRef[i] = rand() % 256;

  pRef++;

  const uint8_t kuiL0   = pRef[-1];
  const uint8_t kuiL1   = pRef[kiStride - 1];
  const uint8_t kuiL2   = pRef[kiStride2 - 1];
  const uint8_t kuiL3   = pRef[kiStride3 - 1];
  const uint16_t kuiL01 = (1 + kuiL0 + kuiL1);
  const uint16_t kuiL12 = (1 + kuiL1 + kuiL2);
  const uint16_t kuiL23 = (1 + kuiL2 + kuiL3);
  const uint8_t kuiHU0  = kuiL01 >> 1;
  const uint8_t kuiHU1  = (kuiL01 + kuiL12) >> 2;
  const uint8_t kuiHU2  = kuiL12 >> 1;
  const uint8_t kuiHU3  = (kuiL12 + kuiL23) >> 2;
  const uint8_t kuiHU4  = kuiL23 >> 1;
  const uint8_t kuiHU5  = (1 + kuiL23 + (kuiL3 << 1)) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  uiV[0] = kuiHU0;
  uiV[1] = kuiHU1;
  uiV[2] = uiV[4] = kuiHU2;
  uiV[3] = uiV[5] = kuiHU3;
  uiV[6] = uiV[8] = kuiHU4;
  uiV[7] = uiV[9] = kuiHU5;
  memset (&uiV[10], kuiL3, 6 * sizeof (uint8_t));

  WelsI4x4LumaPredHU_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  pRef--;

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI4x4LumaPredHD) {
  const int32_t kiStride = rand() % 256 + 16;
  const int32_t kiStride2 = kiStride << 1;
  const int32_t kiStride3 = kiStride + kiStride2;

  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[kiStride3 + kiStride + 1];

  for (int i = 0; i < kiStride3 + kiStride + 1; i++)
    pRef[i] = rand() % 256;

  pRef += kiStride + 1;

  const uint8_t kuiLT  = pRef[-kiStride - 1]; // top-left
  const uint8_t kuiL0  = pRef[-1];
  const uint8_t kuiL1  = pRef[kiStride - 1];
  const uint8_t kuiL2  = pRef[kiStride2 - 1];
  const uint8_t kuiL3  = pRef[kiStride3 - 1];
  const uint8_t kuiT0  = pRef[-kiStride];
  const uint8_t kuiT1  = pRef[1 - kiStride];
  const uint8_t kuiT2  = pRef[2 - kiStride];
  const uint8_t kuiHD0 = (1 + kuiLT + kuiL0) >> 1;
  const uint8_t kuiHD1 = (2 + kuiL0 + (kuiLT << 1) + kuiT0) >> 2;
  const uint8_t kuiHD2 = (2 + kuiLT + (kuiT0 << 1) + kuiT1) >> 2;
  const uint8_t kuiHD3 = (2 + kuiT0 + (kuiT1 << 1) + kuiT2) >> 2;
  const uint8_t kuiHD4 = (1 + kuiL0 + kuiL1) >> 1;
  const uint8_t kuiHD5 = (2 + kuiLT + (kuiL0 << 1) + kuiL1) >> 2;
  const uint8_t kuiHD6 = (1 + kuiL1 + kuiL2) >> 1;
  const uint8_t kuiHD7 = (2 + kuiL0 + (kuiL1 << 1) + kuiL2) >> 2;
  const uint8_t kuiHD8 = (1 + kuiL2 + kuiL3) >> 1;
  const uint8_t kuiHD9 = (2 + kuiL1 + (kuiL2 << 1) + kuiL3) >> 2;
  ENFORCE_STACK_ALIGN_1D (uint8_t, uiV, 16, 16) // TobeCont'd about assign opt as follows
  uiV[0] = uiV[6] = kuiHD0;
  uiV[1] = uiV[7] = kuiHD1;
  uiV[2] = kuiHD2;
  uiV[3] = kuiHD3;
  uiV[4] = uiV[10] = kuiHD4;
  uiV[5] = uiV[11] = kuiHD5;
  uiV[8] = uiV[14] = kuiHD6;
  uiV[9] = uiV[15] = kuiHD7;
  uiV[12] = kuiHD8;
  uiV[13] = kuiHD9;

  WelsI4x4LumaPredHD_c (pPred, pRef, kiStride);

  for (int i = 0; i < 4; i++)
    EXPECT_EQ (LD32 (&pPred[4 * i]), LD32 (&uiV[4 * i]));

  pRef -= kiStride + 1;

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetIChromaPredV) {
  uint8_t* pPred = new uint8_t[64];
  uint8_t* pRef  = new uint8_t[64];
  for (int i = 0; i < 64; i++)
    pRef[i] = rand() % 256 + 1;

  const int32_t kiStride = 0;
  WelsIChromaPredV_c (pPred, pRef, kiStride);

  for (int i = 0; i < 8; i++)
    EXPECT_EQ (LD32 (&pPred[8 * i]), LD32 (&pRef[-kiStride]));

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI16x16LumaPredPlane) {
  const int32_t kiStride = rand() % 16 + 16;

  int32_t i, j;

  uint8_t* pPred = new uint8_t[16 * kiStride];
  uint8_t* pRef  = new uint8_t[16 * kiStride + 1];
  for (i = 0; i < 16 * kiStride + 1; i++)
    pRef[i] = rand() % 256 + 1;

  pRef += kiStride + 1;

  int32_t iA = 0, iB = 0, iC = 0, iH = 0, iV = 0;
  uint8_t* pTop = &pRef[-kiStride];
  uint8_t* pLeft = &pRef[-1];
  int32_t iPredStride = 16;

  for (i = 0; i < 8; i++) {
    iH += (i + 1) * (pTop[8 + i] - pTop[6 - i]);
    iV += (i + 1) * (pLeft[ (8 + i) * kiStride] - pLeft[ (6 - i) * kiStride]);
  }

  iA = (pLeft[15 * kiStride] + pTop[15]) << 4;
  iB = (5 * iH + 32) >> 6;
  iC = (5 * iV + 32) >> 6;

  WelsI16x16LumaPredPlane_c (pPred, pRef, kiStride);
  for (i = 0; i < 16; i++) {
    for (j = 0; j < 16; j++) {
      EXPECT_EQ (pPred[j], (uint8_t)WelsClip1 ((iA + iB * (j - 7) + iC * (i - 7) + 16) >> 5));
    }
    pPred += iPredStride;
  }

  pRef -= kiStride + 1;
  pPred -= (iPredStride * 16);
  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI16x16LumaPredDc) {
  const int32_t kiStride = rand() % 16 + 16;

  int i;

  uint8_t* pPred = new uint8_t[256];
  uint8_t* pRef  = new uint8_t[16 * kiStride];
  for (i = 0; i < 16 * kiStride; i++)
    pRef[i] = rand() % 256 + 1;

  pRef += kiStride;

  int32_t iTmp = (kiStride << 4) - kiStride;
  int32_t iSum = 0;
  i = 15;
  uint8_t uiMean = 0;

  do {
    iSum += pRef[-1 + iTmp] + pRef[-kiStride + i];
    iTmp -= kiStride;
  } while (i-- > 0);
  uiMean = (16 + iSum) >> 5;

  WelsI16x16LumaPredDc_c (pPred, pRef, kiStride);
  for (i = 0; i < 256; i++)
    EXPECT_EQ (pPred[i], uiMean);

  pRef -= kiStride;

  delete []pRef;
  delete []pPred;
}

TEST (GetIntraPredictorTest, TestGetI16x16LumaPredDcTop) {
  const int32_t kiStride = rand() % 16 + 16;

  int i;

  uint8_t* pPred = new uint8_t[256];
  uint8_t* pRef  = new uint8_t[16 * kiStride];
  for (i = 0; i < 16 * kiStride; i++)
    pRef[i] = rand() % 256 + 1;

  pRef += kiStride;

  int32_t iSum = 0;
  i = 15;
  uint8_t uiMean = 0;
  do {
    iSum += pRef[-kiStride + i];
  } while (i-- > 0);
  uiMean = (8 + iSum) >> 4;

  WelsI16x16LumaPredDcTop_c (pPred, pRef, kiStride);
  for (i = 0; i < 256; i++)
    EXPECT_EQ (pPred[i], uiMean);

  pRef -= kiStride;

  delete []pRef;
  delete []pPred;
}