use glam::{Vec3, Vec4};
use runmat_plot::core::{PipelineType, Vertex};
#[test]
fn test_vertex_creation() {
let position = Vec3::new(1.0, 2.0, 3.0);
let color = Vec4::new(1.0, 0.0, 0.0, 1.0);
let vertex = Vertex::new(position, color);
assert_eq!(vertex.position, [1.0, 2.0, 3.0]);
assert_eq!(vertex.color, [1.0, 0.0, 0.0, 1.0]);
assert_eq!(vertex.normal, [0.0, 0.0, 1.0]); assert_eq!(vertex.tex_coords, [0.0, 0.0]); }
#[test]
fn test_vertex_memory_layout() {
let vertex = Vertex::new(Vec3::ZERO, Vec4::ONE);
let bytes: &[u8] = bytemuck::bytes_of(&vertex);
assert_eq!(bytes.len(), std::mem::size_of::<Vertex>());
assert_eq!(std::mem::size_of::<Vertex>(), 48);
}
#[test]
fn test_vertex_buffer_layout() {
let layout = Vertex::desc();
assert_eq!(layout.array_stride, 48); assert_eq!(layout.step_mode, wgpu::VertexStepMode::Vertex);
assert_eq!(layout.attributes.len(), 4);
assert_eq!(layout.attributes[0].offset, 0);
assert_eq!(layout.attributes[0].shader_location, 0);
assert_eq!(layout.attributes[0].format, wgpu::VertexFormat::Float32x3);
assert_eq!(layout.attributes[1].offset, 12); assert_eq!(layout.attributes[1].shader_location, 1);
assert_eq!(layout.attributes[1].format, wgpu::VertexFormat::Float32x4);
}
#[test]
fn test_pipeline_types() {
let point_pipeline = PipelineType::Points;
let line_pipeline = PipelineType::Lines;
let triangle_pipeline = PipelineType::Triangles;
assert_eq!(format!("{point_pipeline:?}"), "Points");
assert_eq!(format!("{line_pipeline:?}"), "Lines");
assert_eq!(format!("{triangle_pipeline:?}"), "Triangles");
}
#[test]
fn test_vertex_creation_batch() {
let vertices = [
Vertex::new(Vec3::new(0.0, 0.0, 0.0), Vec4::new(1.0, 0.0, 0.0, 1.0)), Vertex::new(Vec3::new(1.0, 1.0, 0.0), Vec4::new(0.0, 1.0, 0.0, 1.0)), Vertex::new(Vec3::new(2.0, 0.5, 0.0), Vec4::new(0.0, 0.0, 1.0, 1.0)), ];
assert_eq!(vertices.len(), 3);
for vertex in vertices.iter() {
assert_eq!(vertex.position[2], 0.0); assert_eq!(vertex.color[3], 1.0); assert_eq!(vertex.normal, [0.0, 0.0, 1.0]); }
}
#[test]
fn test_vertex_with_custom_normal_and_uv() {
let mut vertex = Vertex::new(Vec3::X, Vec4::Y);
vertex.normal = [1.0, 0.0, 0.0]; vertex.tex_coords = [0.5, 0.5];
assert_eq!(vertex.normal, [1.0, 0.0, 0.0]);
assert_eq!(vertex.tex_coords, [0.5, 0.5]);
}
#[test]
fn test_vertex_zero_and_one_constants() {
let zero_vertex = Vertex::new(Vec3::ZERO, Vec4::ZERO);
let one_vertex = Vertex::new(Vec3::ONE, Vec4::ONE);
assert_eq!(zero_vertex.position, [0.0, 0.0, 0.0]);
assert_eq!(zero_vertex.color, [0.0, 0.0, 0.0, 0.0]);
assert_eq!(one_vertex.position, [1.0, 1.0, 1.0]);
assert_eq!(one_vertex.color, [1.0, 1.0, 1.0, 1.0]);
}