1+ /* Copyright 2010-present MongoDB Inc.
2+ *
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+
16+ using System ;
17+ using System . Collections . Generic ;
18+ using System . Linq ;
19+ using FluentAssertions ;
20+ using MongoDB . Bson ;
21+ using MongoDB . Bson . Serialization . Attributes ;
22+ using MongoDB . Driver . Core . Misc ;
23+ using MongoDB . Driver . Linq ;
24+ using MongoDB . Driver . TestHelpers ;
25+ using Xunit ;
26+
27+ namespace MongoDB . Driver . Tests . Linq . Linq3Implementation . Translators . ExpressionToAggregationExpressionTranslators . MethodTranslators
28+ {
29+ public class SigmoidMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest < SigmoidMethodToAggregationExpressionTranslatorTests . ClassFixture >
30+ {
31+ public SigmoidMethodToAggregationExpressionTranslatorTests ( ClassFixture fixture )
32+ : base ( fixture , server => server . Supports ( Feature . SigmoidOperator ) )
33+ {
34+ }
35+
36+ [ Fact ]
37+ public void Sigmoid_should_work ( )
38+ {
39+ var collection = Fixture . Collection ;
40+
41+ var queryable = collection
42+ . AsQueryable ( )
43+ . Select ( x => Mql . Sigmoid ( x . X ) ) ;
44+
45+ var stages = Translate ( collection , queryable ) ;
46+ AssertStages ( stages , "{ $project : { _v : { $sigmoid : '$X' }, _id : 0 } }" ) ;
47+
48+ var result = queryable . ToList ( ) ;
49+ result . Should ( ) . BeEquivalentTo ( new [ ] { 0.7310585786300049 , 0.9933071490757153 , 0.999997739675702 , 0.9999999992417439 } ) ;
50+ }
51+
52+ [ Fact ]
53+ public void Sigmoid_with_non_numeric_representation_should_throw ( )
54+ {
55+ var exception = Record . Exception ( ( ) =>
56+ {
57+ var collection = Fixture . Collection ;
58+
59+ var queryable = collection
60+ . AsQueryable ( )
61+ . Select ( x => Mql . Sigmoid ( x . Y ) ) ;
62+
63+ Translate ( collection , queryable ) ;
64+ } ) ;
65+
66+ exception . Should ( ) . BeOfType < ExpressionNotSupportedException > ( ) ;
67+ exception ? . Message . Should ( ) . Contain ( "uses a non-numeric representation" ) ;
68+ }
69+
70+ public class C
71+ {
72+ [ BsonRepresentation ( BsonType . String ) ]
73+ public double Y { get ; set ; }
74+ public double X { get ; set ; }
75+ }
76+
77+ public sealed class ClassFixture : MongoCollectionFixture < C >
78+ {
79+ protected override IEnumerable < C > InitialData =>
80+ [
81+ new ( ) { X = 1.0 } ,
82+ new ( ) { X = 5.0 } ,
83+ new ( ) { X = 13.0 } ,
84+ new ( ) { X = 21.0 } ,
85+ ] ;
86+ }
87+ }
88+ }
0 commit comments