【第三組】用例文檔+功能說明書+技術說明書+(測試文檔),修改時間:2017/07/25

用例文檔:app

  標題:切換夜間模式async

  角色:昏暗環境下游玩的玩家ide

  主要成功場景:函數

    1、玩家從默認模式手動切換到夜間模式單元測試

    步驟:測試

      1)玩家點擊option按鈕跳轉到設置界面this

      2)玩家點擊夜間模式開關,界面變換爲暗色spa

      3)玩家點擊返回按鈕,發現全部界面均爲暗色3d

    2、保存夜間模式狀態code

    步驟:

      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)盡在程序正常關閉時能夠保存夜間模式狀態

 

技術說明書:

  1、日間模式資源字典

    同理,再建立一個夜間模式資源字典

    注意每個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

  2、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>

  3、全局配置與保存

    新建一個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

 

 

  單元測試結果:所有經過

    

相關文章
相關標籤/搜索