【第三组】用例文档+功能说明书+技术说明书+(测试文档),修改时间:2017/07/25

用例文档:

  标题:切换夜间模式

  角色:昏暗环境下游玩的玩家

  主要成功场景:

    一、玩家从默认模式手动切换到夜间模式

    步骤:

      1)玩家点击option按钮跳转到设置界面

      2)玩家点击夜间模式开关,界面变换为暗色

      3)玩家点击返回按钮,发现所有界面均为暗色

    二、保存夜间模式状态

    步骤:

      1)玩家已切换为夜间模式

      2)玩家关闭程序

      3)系统保存夜间模式状态

      4)玩家重新打开程序,发现所有界面均为暗色

  扩展场景:

    自动夜间模式:程序根据系统时间自动切换主题颜色,此功能有开关

 

功能说明书:

  目标:点击夜间模式开关,所有界面变换主题颜色

  用户:在昏暗环境下游玩的玩家

  术语:

    1)Button: 按钮,有点击操作,用于跳转页面

    2)ToggleButton: 切换按钮,有开关两种状态,可在默认模式和夜间模式之间切换

  使用:

    1)打开Geomystery

    2)点击Option按钮,进入设置界面

    3)点击Night Mode 开关,界面颜色从亮色切换到暗色

    4)再次点击开关,界面颜色从暗色切换为亮色

    5)再次点击切换为暗色,点击返回按钮,进入主界面

    6)主界面为暗色背景

    7)关闭Geomystery

    8)第二次打开Geomystery

    9)主界面依然为暗色背景

    10)点击Option按钮,进入设置界面

    11)点击Night Mode 开关,界面颜色从暗色切换到亮色

  边界条件:

    1)模式尽在设置界面切换

    2)尽在程序正常关闭时可以保存夜间模式状态

 

技术说明书:

  一、日间模式资源字典

    同理,再创建一个夜间模式资源字典

    注意每一个brush要定义key

 1 <ResourceDictionary
 2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4     xmlns:local="using:Geomystery.Pages">
 5     <!--日间模式-->
 6     
 7     <!--浅橙色背景-->
 8     <SolidColorBrush x:Key="SystemBackgroundAltHighBrush" Color="#FFFEF2DA"/>
 9     <!--暗紫色背景-->
10     <SolidColorBrush x:Key="SystemBackgroundBaseHighBrush" Color="#FF352D3A"/>
11     <!--紫色文字-->
12     <SolidColorBrush x:Key="TextColorPurple" Color="#FF644385"/>
13     <!--粉紫色渐变-->
14     <LinearGradientBrush x:Key="ColorGradient1" StartPoint="0,0" EndPoint="1,1">
15         <GradientStop Color="#ffc954bf" Offset="0.0" />
16         <GradientStop Color="#ff825be6" Offset="1.0" />
17     </LinearGradientBrush>
18     
19     <Color x:Key="SystemTranslucentBaseHighColor">#FF000000</Color>
20     <Color x:Key="SystemThemeMainColor">#FF0074CE</Color>
21 
22 </ResourceDictionary>
LightThemeDictionary.xaml

    然后需要把资源放在Page

1     <Page.Resources>
2         <ResourceDictionary>
3             <ResourceDictionary.ThemeDictionaries>
4                 <ResourceDictionary x:Key="Light" Source="LightThemeDictionary.xaml"></ResourceDictionary>
5                 <ResourceDictionary x:Key="Dark" Source="DarkThemeDictionary.xaml"></ResourceDictionary>
6             </ResourceDictionary.ThemeDictionaries>
7         </ResourceDictionary>
8     </Page.Resources>
Page.xaml

  二、ViewModel

    建立ViewModel,其中ViewModel继承NotifyProperty

    这个类主要是INotifyPropertyChanged

 1     public class NotifyProperty : INotifyPropertyChanged
 2     {
 3         public NotifyProperty()
 4         {
 5         }
 6 
 7         public void UpdateProper<T>(ref T properValue, T newValue, [CallerMemberName] string properName = "")
 8         {
 9             if (Equals(properValue, newValue))
10             {
11                 return;
12             }
13 
14             properValue = newValue;
15             OnPropertyChanged(properName);
16         }
17 
18         public async void OnPropertyChanged([CallerMemberName] string name = "")
19         {
20             PropertyChangedEventHandler handler = PropertyChanged;
21             await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
22                 () =>
23                 {
24                     handler?.Invoke(this, new PropertyChangedEventArgs(name));
25                 });
26         }
27 
28         public event PropertyChangedEventHandler PropertyChanged;
29     }
NotifyProperty.cs

    模式切换

    ViewModel主要是属性ElementTheme Theme,ElementTheme 有Default,Light,Dark,就是要把key叫light和dark,这样就可以绑定ViewModel修改

 1     public class ViewModel : NotifyProperty
 2     {
 3         public ViewModel()
 4         {
 5             this.Theme= !APPDATA.app_data.ISNIGHT ? ElementTheme.Light : ElementTheme.Dark;
 6         }
 7 
 8         public ElementTheme Theme
 9         {
10             get
11             {
12                 return _theme;
13             }
14             set
15             {
16                 _theme = value;
17                 OnPropertyChanged();
18             }
19         }
20 
21         public bool? AreChecked
22         {
23             set
24             {
25                 _areChecked = value;
26                 Theme = value == false ? ElementTheme.Light : ElementTheme.Dark;
27                 OnPropertyChanged();
28             }
29             get
30             {
31                 return _areChecked;
32             }
33         }
34 
35         private bool? _areChecked = true;
36 
37         private ElementTheme _theme = ElementTheme.Light;
38     }
ViewModel.cs

    在xaml.cs中

1 private ViewModel.ViewModel View { set; get; }=new ViewModel.ViewModel();

    在xaml中

1 <Page
2     RequestedTheme="{x:Bind View.Theme,Mode=OneWay}">
3 
4         <Grid Background="{ThemeResource SystemBackgroundAltHighBrush}"> 
5            <ToggleSwitch HorizontalAlignment="Center" Toggled="ToggleSwitch_OnToggled"></ToggleSwitch>
6        </Grid>

  三、全局配置与保存

    新建一个APPDATA.cs

 1     public class APPDATA
 2     {
 3         public bool ISNIGHT { get; set; }
 4     }
 5 
 6         public void setNight()
 7         {
 8             app_data.ISNIGHT = !app_data.ISNIGHT;
 9             update_views();
10         }

    安装SQLite nutget和vs扩展

 

    在APPDATA.cs中

 1         public static void SAVE()
 2         {
 3             string DbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "APPDATA.db");
 4             var conn = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath);
 5             conn.CreateTable<option_data>();// 创建 option_data 模型对应的表,如果已存在,则忽略该操作。
 6             var db = conn.Table<option_data>();
 7             var k = new option_data();
 8             if (db.Count() == 0) conn.Insert(k);
 9             else
10             {
11                 conn.DeleteAll(typeof(option_data));
12                 conn.Insert(k);
13             }
14         }

 

补充的测试文档:

  测试功能:求鼠标在屏幕上点击一点P

    1)P附近如果有一条直线L,P到L的垂足与P到L最近的距离

    2)P附近如果有一个圆C,P到C最近的距离,还有最近的距离点

      (用来使屏幕上的点击“吸附”在点击附近的元素上)

  单元测试类名:

    Output Coordinate

  单元测试时间:

    

    TestDistanceOfPointAndLine      13毫秒

    TestDistanceOfPointAndCircle      < 1毫秒

  单元测试函数:

    点到直线距离公式

      public void TestDistanceOfPointAndLine()

      OutputCoordinate.DistanceOfPointAndLine(lpo, lv, outerPoint,ref result)

 1         [TestMethod]
 2         public void TestDistanceOfPointAndLine()
 3         {
 4             Vector2 lpo = new Vector2() { X = 0, Y = 10 };                  //直线上的点点
 5             Vector2 lv = new Vector2() { X = 1, Y = 1 } ;                   //直线方向向量(非0)
 6             Vector2 outerPoint = new Vector2() { X = 10, Y = 10 };          //直线上或者直线外的一点
 7             Vector2 result = new Vector2() { X = 1, Y = 1 };                //过outerPoint作l的垂线,result为垂足
 8             float distance = OutputCoordinate.DistanceOfPointAndLine(lpo, lv, outerPoint,ref result);   //点到直线距离
 9             Assert.AreEqual(distance,5 * Math.Sqrt(2), delta);
10             Assert.IsFalse(result.X == 1);
11             Assert.IsFalse(result.Y == 1);
12             float dotMulti = Vector2.Dot(outerPoint - result, lv);          //垂线
13             Assert.AreEqual(dotMulti, 0f, delta);
14             Vector2 result2 = new Vector2();
15             float distance2 = OutputCoordinate.DistanceOfPointAndLine(lpo, lv, result, ref result2);       //垂足在l上
16             Assert.AreEqual(distance2, 0f, delta);
17         }
View Code

点到圆距离公式

  TestDistanceOfPointAndCircle()

  OutputCoordinate.DistanceOfPointAndCircle(center, radius, outerPoint, ref result)

 1         [TestMethod]
 2         public void TestDistanceOfPointAndCircle()
 3         {
 4             Vector2 center = new Vector2() { X = 10, Y = 10 };              //圆心
 5             float radius = 5;                                           //半径(>0)
 6             Vector2 outerPoint = new Vector2() { X = 5, Y = 5 };        //圆外一点或圆内一点或圆上一点
 7             Vector2 result = new Vector2() { X = 0, Y = 0 };            //类似与垂足,result为圆上与outerPoint最接近的点(连接圆心与outerPoint并两端延长,与圆的最近的交点)
 8             float distance = OutputCoordinate.DistanceOfPointAndCircle(center, radius, outerPoint, ref result);     //点到圆最近的距离
 9             Assert.AreEqual(distance, 5 * Math.Sqrt(2) - 5, delta);
10             Assert.IsFalse(result.X == 0);
11             Assert.IsFalse(result.Y == 0);
12             Vector2 result2 = new Vector2();
13             float distance2 = OutputCoordinate.DistanceOfPointAndCircle(center, radius, result, ref result2);       //最近的点在圆上
14             Assert.AreEqual(distance2, 0f, delta);
15         }
View Code

 

 

  单元测试结果:全部通过

    

posted @ 2017-07-25 09:56  HAL0016  阅读(271)  评论(0)    收藏  举报