/*
* Copyright (c) 2026 Huawei Device Co., Ltd.
* 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
*
* http://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.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
interface DisplayDimensions {
width: number;
height: number;
}
function determineOrientation(width: number, height: number): string {
let displayWidth = width;
let displayHeight = height;
let heightBp = displayHeight / displayWidth;
if (displayWidth > displayHeight) {
let temp = displayWidth;
displayWidth = displayHeight;
displayHeight = temp;
}
if (displayWidth >= 600 && heightBp < 0.8) {
return 'LANDSCAPE';
} else {
return 'PORTRAIT';
}
}
export default function localUnitTest() {
describe('localUnitTest', () => {
beforeAll(() => {
});
beforeEach(() => {
});
afterEach(() => {
});
afterAll(() => {
});
it('test_landscape_orientation_width_800_height_600', 0, () => {
let result = determineOrientation(800, 600);
expect(result).assertEqual('LANDSCAPE');
});
it('test_landscape_orientation_width_1200_height_800', 0, () => {
let result = determineOrientation(1200, 800);
expect(result).assertEqual('LANDSCAPE');
});
it('test_landscape_orientation_width_1920_height_1080', 0, () => {
let result = determineOrientation(1920, 1080);
expect(result).assertEqual('LANDSCAPE');
});
it('test_portrait_orientation_width_400_height_800', 0, () => {
let result = determineOrientation(400, 800);
expect(result).assertEqual('PORTRAIT');
});
it('test_portrait_orientation_width_360_height_640', 0, () => {
let result = determineOrientation(360, 640);
expect(result).assertEqual('PORTRAIT');
});
it('test_portrait_orientation_width_600_height_900', 0, () => {
let result = determineOrientation(600, 900);
expect(result).assertEqual('PORTRAIT');
});
it('test_portrait_orientation_width_600_height_480', 0, () => {
let result = determineOrientation(600, 480);
expect(result).assertEqual('PORTRAIT');
});
it('test_width_exactly_600_boundary', 0, () => {
let result = determineOrientation(600, 400);
expect(result).assertEqual('LANDSCAPE');
});
it('test_width_below_600_boundary', 0, () => {
let result = determineOrientation(599, 400);
expect(result).assertEqual('PORTRAIT');
});
it('test_height_width_ratio_exactly_0_8', 0, () => {
let result = determineOrientation(1000, 800);
expect(result).assertEqual('PORTRAIT');
});
it('test_height_width_ratio_below_0_8', 0, () => {
let result = determineOrientation(1000, 700);
expect(result).assertEqual('LANDSCAPE');
});
it('test_height_width_ratio_above_0_8', 0, () => {
let result = determineOrientation(1000, 900);
expect(result).assertEqual('PORTRAIT');
});
it('test_square_display', 0, () => {
let result = determineOrientation(800, 800);
expect(result).assertEqual('PORTRAIT');
});
it('test_foldable_tablet_dimensions', 0, () => {
let result = determineOrientation(1600, 1000);
expect(result).assertEqual('LANDSCAPE');
});
it('test_phone_portrait_dimensions', 0, () => {
let result = determineOrientation(393, 852);
expect(result).assertEqual('PORTRAIT');
});
it('test_orientation_values_are_valid', 0, () => {
let validOrientations: string[] = ['PORTRAIT', 'LANDSCAPE'];
let result = determineOrientation(800, 600);
expect(validOrientations.indexOf(result) >= 0).assertEqual(true);
});
});
}