mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
Tests/LibWeb: Add tests for CSSPixels class
After the CSSPixels implementation evolved from a wrapper of double to a fixed-point saturated math arithmetic implementation, it makes sense to have separate tests for it.
This commit is contained in:
parent
bec07d4af7
commit
0f21b35d1c
2 changed files with 80 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
set(TEST_SOURCES
|
||||
TestCSSIDSpeed.cpp
|
||||
TestCSSPixels.cpp
|
||||
TestHTMLTokenizer.cpp
|
||||
)
|
||||
|
||||
|
|
79
Tests/LibWeb/TestCSSPixels.cpp
Normal file
79
Tests/LibWeb/TestCSSPixels.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <LibWeb/PixelUnits.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
TEST_CASE(addition1)
|
||||
{
|
||||
CSSPixels a(10);
|
||||
CSSPixels b(20);
|
||||
CSSPixels c = a + b;
|
||||
EXPECT_EQ(c, CSSPixels(30));
|
||||
}
|
||||
|
||||
TEST_CASE(subtraction1)
|
||||
{
|
||||
CSSPixels a(30);
|
||||
CSSPixels b(10);
|
||||
CSSPixels c = a - b;
|
||||
EXPECT_EQ(c, CSSPixels(20));
|
||||
}
|
||||
|
||||
TEST_CASE(division1)
|
||||
{
|
||||
CSSPixels a(10);
|
||||
CSSPixels b(5);
|
||||
CSSPixels c = a / b;
|
||||
EXPECT_EQ(c, CSSPixels(2));
|
||||
}
|
||||
|
||||
TEST_CASE(multiplication1)
|
||||
{
|
||||
CSSPixels a(3);
|
||||
CSSPixels b(4);
|
||||
CSSPixels c = a * b;
|
||||
EXPECT_EQ(c, CSSPixels(12));
|
||||
}
|
||||
|
||||
TEST_CASE(addition2)
|
||||
{
|
||||
CSSPixels a(3);
|
||||
a += CSSPixels(2);
|
||||
EXPECT_EQ(a, CSSPixels(5));
|
||||
}
|
||||
|
||||
TEST_CASE(to_double)
|
||||
{
|
||||
CSSPixels a(10);
|
||||
EXPECT_EQ(a.to_double(), 10);
|
||||
}
|
||||
|
||||
TEST_CASE(to_float)
|
||||
{
|
||||
CSSPixels a(11);
|
||||
EXPECT_EQ(a.to_float(), 11);
|
||||
}
|
||||
|
||||
TEST_CASE(to_int)
|
||||
{
|
||||
CSSPixels b(12);
|
||||
EXPECT_EQ(b.to_int(), 12);
|
||||
}
|
||||
|
||||
TEST_CASE(comparison1)
|
||||
{
|
||||
EXPECT_EQ(CSSPixels(1) < CSSPixels(2), true);
|
||||
}
|
||||
|
||||
TEST_CASE(comparison2)
|
||||
{
|
||||
EXPECT_EQ(CSSPixels(123) == CSSPixels(123), true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue