microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.18.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/resource_estimator/src/estimates/optimization/population/tests.rs

94lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use super::{Point, Point2D, Population};
5
6#[test]
7fn test_dominates_should_dominate_by_first_dimension() {
8 let p = Point2D::new(0, 1.0, 1);
9 let other = Point2D::new(1, 1.5, 1);
10 assert!(p.dominates(&other));
11}
12
13#[test]
14fn test_dominates_should_dominate_by_second_dimension() {
15 let p = Point2D::new(0, 1.0, 1);
16 let other = Point2D::new(1, 1.0, 5);
17 assert!(p.dominates(&other));
18}
19
20#[test]
21fn test_dominates_should_dominate_by_both_dimensions() {
22 let p = Point2D::new(0, 1.0, 1);
23 let other = Point2D::new(1, 2.0, 5);
24 assert!(p.dominates(&other));
25}
26
27#[test]
28fn test_dominates_should_not_dominate_first_less_second_greater() {
29 let p = Point2D::new(0, 1.0, 1);
30 let other = Point2D::new(1, 3.0, 0);
31 assert!(!p.dominates(&other));
32}
33
34#[test]
35fn test_dominates_should_not_dominate_first_greater_second_less() {
36 let p = Point2D::new(0, 1.0, 1);
37 let other = Point2D::new(1, 0.0, 2);
38 assert!(!p.dominates(&other));
39}
40
41#[test]
42fn test_dominates_should_not_dominate_itself() {
43 let p = Point2D::new(0, 1.0, 1);
44 let other = Point2D::new(1, 1.0, 1);
45 assert!(!p.dominates(&other));
46}
47
48#[test]
49fn fill() {
50 let mut population = Population::<Point2D<i32>>::new();
51 let p1 = Point2D::new(0, 1.0, 1);
52 let p2 = Point2D::new(1, 0.5, 1);
53 let p3 = Point2D::new(2, 1.1, 0);
54 population.push(p1);
55 population.push(p2);
56 population.push(p3);
57 let items = population.items();
58 assert_eq!(items.len(), 3);
59 assert_eq!(items[0].item, 0);
60 assert_eq!(items[1].item, 1);
61 assert_eq!(items[2].item, 2);
62}
63
64#[test]
65fn fill_and_filter() {
66 let mut population = Population::<Point2D<i32>>::new();
67 let p1 = Point2D::new(0, 1.0, 1);
68 let p2 = Point2D::new(1, 0.5, 1);
69 let p3 = Point2D::new(2, 1.1, 0);
70 population.push(p1);
71 population.push(p2);
72 population.push(p3);
73 population.filter_out_dominated();
74 let items = population.items();
75 assert_eq!(items.len(), 2);
76 assert_eq!(items[0].item + items[1].item, 3);
77}
78
79#[test]
80fn fill_filter_and_sort() {
81 let mut population = Population::<Point2D<i32>>::new();
82 let p1 = Point2D::new(0, 1.0, 1);
83 let p2 = Point2D::new(1, 0.5, 1);
84 let p3 = Point2D::new(2, 1.1, 0);
85 population.push(p1);
86 population.push(p2);
87 population.push(p3);
88 population.filter_out_dominated();
89 population.sort_items();
90 let items = population.items();
91 assert_eq!(items.len(), 2);
92 assert_eq!(items[0].item, 2);
93 assert_eq!(items[1].item, 1);
94}
95